Skip to content

Commit c7a91ff

Browse files
committed
Don't use real dirs in tests
1 parent b5f6323 commit c7a91ff

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

docs/New TypeScript Version.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ For each new flag:
5252
##### Tests
5353

5454
Run `yarn test`.
55+
5556
Tests can fail between TS builds, for example snapshot tests in packages which have compiler errors or LSP responses in them.
56-
Run `yarn update-test-snapshots` to try auto-update all snapshots, otherwise use `yarn workspace [package_name] test -u` for 1 package.
57+
Run `yarn build; yarn update-test-snapshots` to try auto-update all snapshots, otherwise use `yarn workspace [package_name] test -u` for 1 package.
5758

5859
### RC
5960

packages/ts-twoslasher/test/fixtures.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readdirSync, readFileSync, lstatSync } from "fs"
22
import { join, extname, parse } from "path"
33
import { toMatchFile } from "jest-file-snapshot"
4-
import { twoslasher } from "../src/index"
4+
import { twoslasher, TwoSlashReturn } from "../src/index"
55
import { format } from "prettier"
66

77
expect.extend({ toMatchFile })
@@ -28,7 +28,7 @@ describe("with fixtures", () => {
2828
const file = readFileSync(fixture, "utf8")
2929

3030
const fourslashed = twoslasher(file, extname(fixtureName).substr(1))
31-
const jsonString = format(JSON.stringify(fourslashed), { parser: "json" })
31+
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
3232
expect(jsonString).toMatchFile(result)
3333
})
3434
})
@@ -47,7 +47,7 @@ describe("with fixtures", () => {
4747
const file = readFileSync(fixture, "utf8")
4848

4949
const fourslashed = twoslasher(file, extname(fixtureName).substr(1))
50-
const jsonString = format(JSON.stringify(fourslashed), { parser: "json" })
50+
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
5151
expect(jsonString).toMatchFile(result)
5252
})
5353
})
@@ -66,7 +66,7 @@ describe("with fixtures", () => {
6666
const file = readFileSync(fixture, "utf8")
6767

6868
const fourslashed = twoslasher(file, extname(fixtureName).substr(1))
69-
const jsonString = format(JSON.stringify(fourslashed), { parser: "json" })
69+
const jsonString = format(JSON.stringify(cleanFixture(fourslashed)), { parser: "json" })
7070
expect(jsonString).toMatchFile(result)
7171
})
7272
})
@@ -97,3 +97,11 @@ describe("with fixtures", () => {
9797
})
9898
})
9999
})
100+
101+
const cleanFixture = (ts: TwoSlashReturn) => {
102+
const wd = process.cwd()
103+
ts.staticQuickInfos.forEach(info => {
104+
info.text = info.text.replace(new RegExp(wd, "g"), "[home]")
105+
})
106+
return ts
107+
}

packages/ts-twoslasher/test/results/tests/crossExports.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"targetString": "length"
4141
},
4242
{
43-
"text": "var module: {\n \"\\\"/Users/ortatherox/dev/typescript/new-website/packages/ts-twoslasher/utilFunctions\\\"\": typeof import(\"/Users/ortatherox/dev/typescript/new-website/packages/ts-twoslasher/utilFunctions\");\n}",
43+
"text": "var module: {\n \"\\\"[home]/utilFunctions\\\"\": typeof import(\"[home]/utilFunctions\");\n}",
4444
"docs": "",
4545
"start": 73,
4646
"length": 6,
@@ -49,7 +49,7 @@
4949
"targetString": "module"
5050
},
5151
{
52-
"text": "module \"/Users/ortatherox/dev/typescript/new-website/packages/ts-twoslasher/utilFunctions\"",
52+
"text": "module \"[home]/utilFunctions\"",
5353
"docs": "",
5454
"start": 80,
5555
"length": 7,

0 commit comments

Comments
 (0)