-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a3c896
commit c4b4629
Showing
4 changed files
with
79 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,66 @@ | ||
import { | ||
createProjectBuildProvider, | ||
serveDir, | ||
serveToolboxRunner, | ||
} from '@ph.fritsche/toolbox' | ||
import {NodeTestConductor} from '@ph.fritsche/toolbox/dist/conductor/NodeTestConductor.js' | ||
import {ChromeTestConductor} from '@ph.fritsche/toolbox/dist/conductor/ChromeTestConductor.js' | ||
import {ConsoleReporter} from '@ph.fritsche/toolbox/dist/reporter/ConsoleReporter.js' | ||
import {ReporterServer} from '@ph.fritsche/toolbox/dist/reporter/ReporterServer.js' | ||
import {TestRunStack} from '@ph.fritsche/toolbox/dist/reporter/TestRunStack.js' | ||
|
||
import IstanbulLibCoverage from 'istanbul-lib-coverage' | ||
import IstanbulLibReport from 'istanbul-lib-report' | ||
import IstanbulLibSourceMaps from 'istanbul-lib-source-maps' | ||
import IstanbulReports from 'istanbul-reports' | ||
import { serveDir, setupChromeConductor, setupNodeConductor, setupSourceModuleLoader, setupToolboxTester } from '@ph.fritsche/toolbox' | ||
|
||
const tsConfigFile = './tests/tsconfig.json' | ||
|
||
const toolbox = await serveToolboxRunner() | ||
const env = await serveDir('testenv') | ||
|
||
const {buildProvider, fileProvider, fileServer, onBuildDone} = | ||
createProjectBuildProvider(['src', 'tests'], { | ||
tsConfigFile, | ||
globals: { | ||
'@testing-library/dom': 'DomTestingLibrary', | ||
'@testing-library/react': 'ReactTestingLibrary', | ||
react: 'React', | ||
'react-dom': 'ReactDom', | ||
}, | ||
}) | ||
|
||
for (const {builder} of buildProvider.builders) { | ||
builder.emitter.addListener('start', ({type, buildId, inputFiles}) => | ||
console.log(builder.id, {type, buildId, inputFiles: inputFiles.size}), | ||
) | ||
builder.emitter.addListener( | ||
'complete', | ||
({type, buildId, inputFiles, outputFiles}) => | ||
console.log(builder.id, { | ||
type, | ||
buildId, | ||
inputFiles: inputFiles.size, | ||
outputFiles: outputFiles.size, | ||
}), | ||
) | ||
builder.emitter.addListener('error', ({type, buildId, error}) => | ||
console.log(builder.id, {type, buildId, error}), | ||
) | ||
builder.emitter.addListener('done', ({type, buildId}) => | ||
console.log(builder.id, {type, buildId}), | ||
) | ||
} | ||
buildProvider | ||
.getBuilder('dependencies') | ||
.builder.emitter.addListener('start', ({inputFiles}) => | ||
console.log('dependencies', inputFiles.keys()), | ||
) | ||
|
||
const filter = f => | ||
f.startsWith('tests') && | ||
/(?<!\.json)\.js$/.test(f) && | ||
!/\/_.+(?<!\.test)\.[jt]sx?$/.test(f) | ||
|
||
const reporterServer = new ReporterServer() | ||
await reporterServer.registerFileServer(toolbox.server) | ||
await reporterServer.registerFileServer(env.server) | ||
await reporterServer.registerFileServer(fileServer) | ||
|
||
const consoleReporter = new ConsoleReporter() | ||
consoleReporter.config.result = !!process.env.CI | ||
consoleReporter.connect(reporterServer) | ||
|
||
const conductors = [ | ||
new ChromeTestConductor( | ||
reporterServer, | ||
toolbox.url, | ||
'Chrome, DTL8, React18', | ||
const tester = await setupToolboxTester( | ||
[ | ||
'src', | ||
'tests', | ||
], | ||
[ | ||
setupNodeConductor('Node, DTL8, React18', [ | ||
new URL('../testenv/node.js', import.meta.url), | ||
new URL('./libs/dom8/index.bundle.js', env.url), | ||
new URL('./libs/react18/index.bundle.js', env.url), | ||
]), | ||
setupNodeConductor('Node, DTL8, React17', [ | ||
new URL('../testenv/node.js', import.meta.url), | ||
new URL('./libs/dom8/index.bundle.js', env.url), | ||
new URL('./libs/react17/index.bundle.js', env.url), | ||
]), | ||
setupChromeConductor('Chrome, DTL8, React18', [ | ||
new URL('./browser.bundle.js', env.url), | ||
new URL('./libs/dom8/index.bundle.js', env.url), | ||
new URL('./libs/react18/index.bundle.js', env.url), | ||
]) | ||
], | ||
[ | ||
{server: env.url, paths: ['browser.bundle.js']}, | ||
{ | ||
server: env.url, | ||
paths: ['libs/dom8/index.bundle.js', 'libs/react18/index.bundle.js'], | ||
}, | ||
await setupSourceModuleLoader({ | ||
globals: { | ||
'@testing-library/dom': 'DomTestingLibrary', | ||
'@testing-library/react': 'ReactTestingLibrary', | ||
'react': 'React', | ||
'react-dom': 'ReactDom', | ||
}, | ||
}), | ||
], | ||
), | ||
new NodeTestConductor(reporterServer, toolbox.url, 'Node, DTL8, React18', [ | ||
{server: new URL(`file://${env.provider.origin}`), paths: ['node.js']}, | ||
{ | ||
server: env.url, | ||
paths: ['libs/dom8/index.bundle.js', 'libs/react18/index.bundle.js'], | ||
}, | ||
]), | ||
] | ||
|
||
if (process.env.CI) { | ||
conductors.push( | ||
new NodeTestConductor(reporterServer, toolbox.url, 'Node, DTL8, React17', [ | ||
{server: new URL(`file://${env.provider.origin}`), paths: ['node.js']}, | ||
{ | ||
server: env.url, | ||
paths: ['libs/dom8/index.bundle.js', 'libs/react17/index.bundle.js'], | ||
}, | ||
]), | ||
) | ||
} | ||
|
||
onBuildDone(async () => { | ||
const files = { | ||
server: await fileServer.url, | ||
paths: Array.from(fileProvider.files.keys()).filter(filter), | ||
} | ||
const runs = conductors.map(c => c.createTestRun(files)) | ||
const stack = new TestRunStack(runs.map(r => r.run)) | ||
|
||
for (const r of runs) { | ||
await r.exec() | ||
} | ||
|
||
await stack.then() | ||
|
||
const coverageMap = IstanbulLibCoverage.createCoverageMap() | ||
for (const run of stack.runs) { | ||
for (const coverage of run.coverage.values()) { | ||
coverageMap.merge(coverage) | ||
setExitCode: false, | ||
} | ||
} | ||
|
||
const sourceStore = IstanbulLibSourceMaps.createSourceMapStore() | ||
const reportContext = IstanbulLibReport.createContext({ | ||
coverageMap: await sourceStore.transformCoverage(coverageMap), | ||
dir: fileProvider.origin, | ||
sourceFinder: sourceStore.sourceFinder, | ||
defaultSummarizer: 'nested', | ||
watermarks: { | ||
branches: [80, 100], | ||
functions: [80, 100], | ||
lines: [80, 100], | ||
statements: [80, 100], | ||
}, | ||
}) | ||
) | ||
|
||
tester.connectCoverageReporter(async map => { | ||
const sourceStore = IstanbulLibSourceMaps.createSourceMapStore() | ||
const reportContext = IstanbulLibReport.createContext({ | ||
coverageMap: await sourceStore.transformCoverage(map), | ||
sourceFinder: sourceStore.sourceFinder, | ||
defaultSummarizer: 'nested', | ||
watermarks: { | ||
branches: [80, 100], | ||
functions: [80, 100], | ||
lines: [80, 100], | ||
statements: [80, 100], | ||
}, | ||
}) | ||
|
||
IstanbulReports.create('text').execute(reportContext) | ||
}) | ||
|
||
IstanbulReports.create('text').execute(reportContext) | ||
await tester.start() | ||
|
||
if (process.env.CI) { | ||
toolbox.server.close() | ||
env.server.close() | ||
fileServer.close() | ||
buildProvider.close() | ||
reporterServer.close() | ||
conductors.forEach(c => c.close()) | ||
} | ||
}) | ||
if (process.env.CI) { | ||
await env.server.close() | ||
} |