Skip to content

Commit 315b72d

Browse files
author
Andy
authored
Use it instead of describe for tests (microsoft#16172)
* Use `it` instead of `describe` for tests * Create SourceFiles lazily * Use before() hooks
1 parent b8d39d7 commit 315b72d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/harness/unittests/printer.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ namespace ts {
1414

1515
describe("printFile", () => {
1616
const printsCorrectly = makePrintsCorrectly("printsFileCorrectly");
17-
const sourceFile = createSourceFile("source.ts", `
17+
// Avoid eagerly creating the sourceFile so that `createSourceFile` doesn't run unless one of these tests is run.
18+
let sourceFile: SourceFile;
19+
before(() => sourceFile = createSourceFile("source.ts", `
1820
interface A<T> {
1921
// comment1
2022
readonly prop?: T;
@@ -48,8 +50,7 @@ namespace ts {
4850
4951
// comment10
5052
function functionWithDefaultArgValue(argument: string = "defaultValue"): void { }
51-
`, ScriptTarget.ES2015);
52-
53+
`, ScriptTarget.ES2015));
5354
printsCorrectly("default", {}, printer => printer.printFile(sourceFile));
5455
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printFile(sourceFile));
5556

@@ -59,7 +60,8 @@ namespace ts {
5960

6061
describe("printBundle", () => {
6162
const printsCorrectly = makePrintsCorrectly("printsBundleCorrectly");
62-
const bundle = createBundle([
63+
let bundle: Bundle;
64+
before(() => bundle = createBundle([
6365
createSourceFile("a.ts", `
6466
/*! [a.ts] */
6567
@@ -72,14 +74,15 @@ namespace ts {
7274
// comment1
7375
const b = 2;
7476
`, ScriptTarget.ES2015)
75-
]);
77+
]));
7678
printsCorrectly("default", {}, printer => printer.printBundle(bundle));
7779
printsCorrectly("removeComments", { removeComments: true }, printer => printer.printBundle(bundle));
7880
});
7981

8082
describe("printNode", () => {
8183
const printsCorrectly = makePrintsCorrectly("printsNodeCorrectly");
82-
const sourceFile = createSourceFile("source.ts", "", ScriptTarget.ES2015);
84+
let sourceFile: SourceFile;
85+
before(() => sourceFile = createSourceFile("source.ts", "", ScriptTarget.ES2015));
8386
// tslint:disable boolean-trivia
8487
const syntheticNode = createClassDeclaration(
8588
undefined,

0 commit comments

Comments
 (0)