Skip to content

Commit cb13465

Browse files
authored
feature: add node module reference e2e test (#456)
1 parent 70668b2 commit cb13465

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { Test } from '@lvce-editor/test-with-playwright'
2+
3+
export const name = 'typescript.references-node-module'
4+
5+
export const skip = 1
6+
7+
export const test: Test = async ({ FileSystem, Main, Editor, Locator, expect }) => {
8+
// arrange
9+
const tmpDir = await FileSystem.getTmpDir()
10+
await FileSystem.writeFile(
11+
`${tmpDir}/tsconfig.json`,
12+
JSON.stringify(
13+
{
14+
compilerOptions: {
15+
lib: ['esnext', 'dom'],
16+
types: [],
17+
},
18+
},
19+
null,
20+
2,
21+
),
22+
)
23+
await FileSystem.writeFile(
24+
`${tmpDir}/package.json`,
25+
JSON.stringify(
26+
{
27+
dependencies: {
28+
lodash: '^1.0.0',
29+
},
30+
},
31+
null,
32+
2,
33+
),
34+
)
35+
await FileSystem.mkdir(`${tmpDir}/node_modules`)
36+
await FileSystem.mkdir(`${tmpDir}/node_modules/lodash`)
37+
await FileSystem.writeFile(
38+
`${tmpDir}/node_modules/lodash/package.json`,
39+
JSON.stringify({
40+
name: 'lodash',
41+
main: 'index.js',
42+
type: 'module',
43+
}),
44+
)
45+
await FileSystem.writeFile(`${tmpDir}/node_modules/lodash/index.js`, `export const add = (a,b) => a + b`)
46+
await FileSystem.writeFile(
47+
`${tmpDir}/test.ts`,
48+
`import { add } from 'lodash'
49+
50+
add(1,2)
51+
`,
52+
)
53+
await Main.openUri(`${tmpDir}/test.ts`)
54+
await Editor.setCursor(2, 2)
55+
56+
// act
57+
await Editor.findAllReferences()
58+
59+
// assert
60+
const viewletLocations = Locator('.Locations')
61+
await expect(viewletLocations).toBeVisible()
62+
const viewletReferencesMessage = Locator('.LocationsMessage')
63+
await expect(viewletReferencesMessage).toHaveText('3 results in 2 files')
64+
const referenceItems = viewletLocations.locator('.TreeItem')
65+
const referenceItemOne = referenceItems.nth(0)
66+
await expect(referenceItemOne).toHaveText('test.ts')
67+
const referenceItemTwo = referenceItems.nth(1)
68+
await expect(referenceItemTwo).toHaveText(`import { add } from './add.ts'`)
69+
}

0 commit comments

Comments
 (0)