|
1 |
| -import { |
2 |
| - createProjectBuildProvider, |
3 |
| - serveDir, |
4 |
| - serveToolboxRunner, |
5 |
| -} from '@ph.fritsche/toolbox' |
6 |
| -import {NodeTestConductor} from '@ph.fritsche/toolbox/dist/conductor/NodeTestConductor.js' |
7 |
| -import {ChromeTestConductor} from '@ph.fritsche/toolbox/dist/conductor/ChromeTestConductor.js' |
8 |
| -import {ConsoleReporter} from '@ph.fritsche/toolbox/dist/reporter/ConsoleReporter.js' |
9 |
| -import {ReporterServer} from '@ph.fritsche/toolbox/dist/reporter/ReporterServer.js' |
10 |
| -import {TestRunStack} from '@ph.fritsche/toolbox/dist/reporter/TestRunStack.js' |
11 |
| - |
12 |
| -import IstanbulLibCoverage from 'istanbul-lib-coverage' |
13 | 1 | import IstanbulLibReport from 'istanbul-lib-report'
|
14 | 2 | import IstanbulLibSourceMaps from 'istanbul-lib-source-maps'
|
15 | 3 | import IstanbulReports from 'istanbul-reports'
|
| 4 | +import { serveDir, setupChromeConductor, setupNodeConductor, setupSourceModuleLoader, setupToolboxTester } from '@ph.fritsche/toolbox' |
16 | 5 |
|
17 |
| -const tsConfigFile = './tests/tsconfig.json' |
18 |
| - |
19 |
| -const toolbox = await serveToolboxRunner() |
20 | 6 | const env = await serveDir('testenv')
|
21 | 7 |
|
22 |
| -const {buildProvider, fileProvider, fileServer, onBuildDone} = |
23 |
| - createProjectBuildProvider(['src', 'tests'], { |
24 |
| - tsConfigFile, |
25 |
| - globals: { |
26 |
| - '@testing-library/dom': 'DomTestingLibrary', |
27 |
| - '@testing-library/react': 'ReactTestingLibrary', |
28 |
| - react: 'React', |
29 |
| - 'react-dom': 'ReactDom', |
30 |
| - }, |
31 |
| - }) |
32 |
| - |
33 |
| -for (const {builder} of buildProvider.builders) { |
34 |
| - builder.emitter.addListener('start', ({type, buildId, inputFiles}) => |
35 |
| - console.log(builder.id, {type, buildId, inputFiles: inputFiles.size}), |
36 |
| - ) |
37 |
| - builder.emitter.addListener( |
38 |
| - 'complete', |
39 |
| - ({type, buildId, inputFiles, outputFiles}) => |
40 |
| - console.log(builder.id, { |
41 |
| - type, |
42 |
| - buildId, |
43 |
| - inputFiles: inputFiles.size, |
44 |
| - outputFiles: outputFiles.size, |
45 |
| - }), |
46 |
| - ) |
47 |
| - builder.emitter.addListener('error', ({type, buildId, error}) => |
48 |
| - console.log(builder.id, {type, buildId, error}), |
49 |
| - ) |
50 |
| - builder.emitter.addListener('done', ({type, buildId}) => |
51 |
| - console.log(builder.id, {type, buildId}), |
52 |
| - ) |
53 |
| -} |
54 |
| -buildProvider |
55 |
| - .getBuilder('dependencies') |
56 |
| - .builder.emitter.addListener('start', ({inputFiles}) => |
57 |
| - console.log('dependencies', inputFiles.keys()), |
58 |
| - ) |
59 |
| - |
60 |
| -const filter = f => |
61 |
| - f.startsWith('tests') && |
62 |
| - /(?<!\.json)\.js$/.test(f) && |
63 |
| - !/\/_.+(?<!\.test)\.[jt]sx?$/.test(f) |
64 |
| - |
65 |
| -const reporterServer = new ReporterServer() |
66 |
| -await reporterServer.registerFileServer(toolbox.server) |
67 |
| -await reporterServer.registerFileServer(env.server) |
68 |
| -await reporterServer.registerFileServer(fileServer) |
69 |
| - |
70 |
| -const consoleReporter = new ConsoleReporter() |
71 |
| -consoleReporter.config.result = !!process.env.CI |
72 |
| -consoleReporter.connect(reporterServer) |
73 |
| - |
74 |
| -const conductors = [ |
75 |
| - new ChromeTestConductor( |
76 |
| - reporterServer, |
77 |
| - toolbox.url, |
78 |
| - 'Chrome, DTL8, React18', |
| 8 | +const tester = await setupToolboxTester( |
| 9 | + [ |
| 10 | + 'src', |
| 11 | + 'tests', |
| 12 | + ], |
| 13 | + [ |
| 14 | + setupNodeConductor('Node, DTL8, React18', [ |
| 15 | + new URL('../testenv/node.js', import.meta.url), |
| 16 | + new URL('./libs/dom8/index.bundle.js', env.url), |
| 17 | + new URL('./libs/react18/index.bundle.js', env.url), |
| 18 | + ]), |
| 19 | + setupNodeConductor('Node, DTL8, React17', [ |
| 20 | + new URL('../testenv/node.js', import.meta.url), |
| 21 | + new URL('./libs/dom8/index.bundle.js', env.url), |
| 22 | + new URL('./libs/react17/index.bundle.js', env.url), |
| 23 | + ]), |
| 24 | + setupChromeConductor('Chrome, DTL8, React18', [ |
| 25 | + new URL('./browser.bundle.js', env.url), |
| 26 | + new URL('./libs/dom8/index.bundle.js', env.url), |
| 27 | + new URL('./libs/react18/index.bundle.js', env.url), |
| 28 | + ]) |
| 29 | + ], |
79 | 30 | [
|
80 |
| - {server: env.url, paths: ['browser.bundle.js']}, |
81 |
| - { |
82 |
| - server: env.url, |
83 |
| - paths: ['libs/dom8/index.bundle.js', 'libs/react18/index.bundle.js'], |
84 |
| - }, |
| 31 | + await setupSourceModuleLoader({ |
| 32 | + globals: { |
| 33 | + '@testing-library/dom': 'DomTestingLibrary', |
| 34 | + '@testing-library/react': 'ReactTestingLibrary', |
| 35 | + 'react': 'React', |
| 36 | + 'react-dom': 'ReactDom', |
| 37 | + }, |
| 38 | + }), |
85 | 39 | ],
|
86 |
| - ), |
87 |
| - new NodeTestConductor(reporterServer, toolbox.url, 'Node, DTL8, React18', [ |
88 |
| - {server: new URL(`file://${env.provider.origin}`), paths: ['node.js']}, |
89 | 40 | {
|
90 |
| - server: env.url, |
91 |
| - paths: ['libs/dom8/index.bundle.js', 'libs/react18/index.bundle.js'], |
92 |
| - }, |
93 |
| - ]), |
94 |
| -] |
95 |
| - |
96 |
| -if (process.env.CI) { |
97 |
| - conductors.push( |
98 |
| - new NodeTestConductor(reporterServer, toolbox.url, 'Node, DTL8, React17', [ |
99 |
| - {server: new URL(`file://${env.provider.origin}`), paths: ['node.js']}, |
100 |
| - { |
101 |
| - server: env.url, |
102 |
| - paths: ['libs/dom8/index.bundle.js', 'libs/react17/index.bundle.js'], |
103 |
| - }, |
104 |
| - ]), |
105 |
| - ) |
106 |
| -} |
107 |
| - |
108 |
| -onBuildDone(async () => { |
109 |
| - const files = { |
110 |
| - server: await fileServer.url, |
111 |
| - paths: Array.from(fileProvider.files.keys()).filter(filter), |
112 |
| - } |
113 |
| - const runs = conductors.map(c => c.createTestRun(files)) |
114 |
| - const stack = new TestRunStack(runs.map(r => r.run)) |
115 |
| - |
116 |
| - for (const r of runs) { |
117 |
| - await r.exec() |
118 |
| - } |
119 |
| - |
120 |
| - await stack.then() |
121 |
| - |
122 |
| - const coverageMap = IstanbulLibCoverage.createCoverageMap() |
123 |
| - for (const run of stack.runs) { |
124 |
| - for (const coverage of run.coverage.values()) { |
125 |
| - coverageMap.merge(coverage) |
| 41 | + setExitCode: false, |
126 | 42 | }
|
127 |
| - } |
128 |
| - |
129 |
| - const sourceStore = IstanbulLibSourceMaps.createSourceMapStore() |
130 |
| - const reportContext = IstanbulLibReport.createContext({ |
131 |
| - coverageMap: await sourceStore.transformCoverage(coverageMap), |
132 |
| - dir: fileProvider.origin, |
133 |
| - sourceFinder: sourceStore.sourceFinder, |
134 |
| - defaultSummarizer: 'nested', |
135 |
| - watermarks: { |
136 |
| - branches: [80, 100], |
137 |
| - functions: [80, 100], |
138 |
| - lines: [80, 100], |
139 |
| - statements: [80, 100], |
140 |
| - }, |
141 |
| - }) |
| 43 | +) |
| 44 | + |
| 45 | +tester.connectCoverageReporter(async map => { |
| 46 | + const sourceStore = IstanbulLibSourceMaps.createSourceMapStore() |
| 47 | + const reportContext = IstanbulLibReport.createContext({ |
| 48 | + coverageMap: await sourceStore.transformCoverage(map), |
| 49 | + sourceFinder: sourceStore.sourceFinder, |
| 50 | + defaultSummarizer: 'nested', |
| 51 | + watermarks: { |
| 52 | + branches: [80, 100], |
| 53 | + functions: [80, 100], |
| 54 | + lines: [80, 100], |
| 55 | + statements: [80, 100], |
| 56 | + }, |
| 57 | + }) |
| 58 | + |
| 59 | + IstanbulReports.create('text').execute(reportContext) |
| 60 | +}) |
142 | 61 |
|
143 |
| - IstanbulReports.create('text').execute(reportContext) |
| 62 | +await tester.start() |
144 | 63 |
|
145 |
| - if (process.env.CI) { |
146 |
| - toolbox.server.close() |
147 |
| - env.server.close() |
148 |
| - fileServer.close() |
149 |
| - buildProvider.close() |
150 |
| - reporterServer.close() |
151 |
| - conductors.forEach(c => c.close()) |
152 |
| - } |
153 |
| -}) |
| 64 | +if (process.env.CI) { |
| 65 | + await env.server.close() |
| 66 | +} |
0 commit comments