From 315b72d035a60ef23443c748032220dfc92ce222 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 31 May 2017 15:31:35 -0700 Subject: [PATCH] Use `it` instead of `describe` for tests (#16172) * Use `it` instead of `describe` for tests * Create SourceFiles lazily * Use before() hooks --- src/harness/unittests/printer.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/harness/unittests/printer.ts b/src/harness/unittests/printer.ts index a9af46b2780..4bdafe04ba1 100644 --- a/src/harness/unittests/printer.ts +++ b/src/harness/unittests/printer.ts @@ -14,7 +14,9 @@ namespace ts { describe("printFile", () => { const printsCorrectly = makePrintsCorrectly("printsFileCorrectly"); - const sourceFile = createSourceFile("source.ts", ` + // Avoid eagerly creating the sourceFile so that `createSourceFile` doesn't run unless one of these tests is run. + let sourceFile: SourceFile; + before(() => sourceFile = createSourceFile("source.ts", ` interface A { // comment1 readonly prop?: T; @@ -48,8 +50,7 @@ namespace ts { // comment10 function functionWithDefaultArgValue(argument: string = "defaultValue"): void { } - `, ScriptTarget.ES2015); - + `, ScriptTarget.ES2015)); printsCorrectly("default", {}, printer => printer.printFile(sourceFile)); printsCorrectly("removeComments", { removeComments: true }, printer => printer.printFile(sourceFile)); @@ -59,7 +60,8 @@ namespace ts { describe("printBundle", () => { const printsCorrectly = makePrintsCorrectly("printsBundleCorrectly"); - const bundle = createBundle([ + let bundle: Bundle; + before(() => bundle = createBundle([ createSourceFile("a.ts", ` /*! [a.ts] */ @@ -72,14 +74,15 @@ namespace ts { // comment1 const b = 2; `, ScriptTarget.ES2015) - ]); + ])); printsCorrectly("default", {}, printer => printer.printBundle(bundle)); printsCorrectly("removeComments", { removeComments: true }, printer => printer.printBundle(bundle)); }); describe("printNode", () => { const printsCorrectly = makePrintsCorrectly("printsNodeCorrectly"); - const sourceFile = createSourceFile("source.ts", "", ScriptTarget.ES2015); + let sourceFile: SourceFile; + before(() => sourceFile = createSourceFile("source.ts", "", ScriptTarget.ES2015)); // tslint:disable boolean-trivia const syntheticNode = createClassDeclaration( undefined,