-
Notifications
You must be signed in to change notification settings - Fork 340
/
file-visitor-module.test.mjs
84 lines (75 loc) · 2.26 KB
/
file-visitor-module.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { join } from 'path'
import { format } from 'util'
import test from 'ava'
import mock, { restore } from 'mock-fs'
import snapshots from '../../tests/utils/snapshots.js'
import { DependencyGraph, fileVisitor } from '../project-graph/index.mjs'
import { esModuleMockedFileSystem } from './utils/file-systems.mjs'
test.before(() => {
mock(esModuleMockedFileSystem)
})
test.after(() => {
restore()
})
test('should visit the files that are dependents from the provided main file based on imports', (t) => {
const graph = new DependencyGraph()
fileVisitor(join('tests/a.test.js'), { graph, visitorPlugins: [] })
t.is(
snapshots.normalize(graph.visualize().to_dot()),
`digraph G {
"src/nested/b.js";
"src/nested/a.js";
"src/c/index.js";
"src/d.js";
"tests/a.test.js";
"src/nested/a.js" -> "src/nested/b.js";
"src/nested/a.js" -> "src/c/index.js";
"src/c/index.js" -> "src/d.js";
"tests/a.test.js" -> "src/nested/a.js";
}
`,
)
})
test('should merge the graph with files from a different entry point based on imports', (t) => {
const graph = new DependencyGraph()
fileVisitor(join('tests/a.test.js'), { graph, visitorPlugins: [] })
fileVisitor(join('tests/c.test.js'), { graph, visitorPlugins: [] })
t.is(
snapshots.normalize(graph.visualize().to_dot()),
`digraph G {
"src/nested/b.js";
"src/nested/a.js";
"src/c/index.js";
"src/d.js";
"tests/a.test.js";
"tests/c.test.js";
"tests/utils.js";
"src/nested/a.js" -> "src/nested/b.js";
"src/nested/a.js" -> "src/c/index.js";
"src/c/index.js" -> "src/d.js";
"tests/a.test.js" -> "src/nested/a.js";
"tests/c.test.js" -> "src/c/index.js";
"tests/c.test.js" -> "tests/utils.js";
}
`,
)
})
test('should build a list of affected files based on a file with imports', (t) => {
const graph = new DependencyGraph()
fileVisitor(join('tests/a.test.js'), { graph, visitorPlugins: [] })
fileVisitor(join('tests/c.test.js'), { graph, visitorPlugins: [] })
t.is(
format([...graph.affected([join('src/d.js')])]).replace(/\\+/gm, '/'),
`[
'src/d.js',
'src/c/index.js',
'src/nested/a.js',
'tests/a.test.js',
'tests/c.test.js'
]`,
)
t.is(
format([...graph.affected([join('tests/utils.js')])]).replace(/\\+/gm, '/'),
"[ 'tests/utils.js', 'tests/c.test.js' ]",
)
})