-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert-integration.js
52 lines (38 loc) · 1.8 KB
/
assert-integration.js
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
// loads the plugin in Rollup and Webpack, runs the build tools and assert that everything works
const fs = require('fs');
const {execSync} = require('child_process');
const runIntegrationTest = (pluginInfo) => {
execSync(pluginInfo.testCommand);
execSync(pluginInfo.testCommand);
if (!fs.existsSync(`packages/${pluginInfo.directoryName}/stats/build-log.json`)) {
throw new Error('Build log file was not found.');
}
const logFileContent = fs.readFileSync(`packages/${pluginInfo.directoryName}/stats/build-log.json`);
const logs = JSON.parse(logFileContent.toString());
if (logs.length !== 2) {
throw new Error('Build log file was empty or not correctly written');
}
const newLogs = logs.map((log) => Object.assign(log, {date: '0-0-2000'}));
fs.writeFileSync(`packages/${pluginInfo.directoryName}/stats/build-log.json`, JSON.stringify(newLogs));
execSync(pluginInfo.testCommand);
const summaryLogsContent = fs.readFileSync(`packages/${pluginInfo.directoryName}/stats/build-stats-summary.json`);
const summaryLogs = JSON.parse(summaryLogsContent.toString());
if (summaryLogs.length !== 1) {
throw new Error('Summary log file was empty or not correctly written');
}
};
const webpack4 = {
directoryName: 'webpack-plugin/integration-test/webpack4',
testCommand: 'lerna run test:webpack4 --stream --scope webpack-plugin-build-statistics'
};
const webpack5 = {
directoryName: 'webpack-plugin/integration-test/webpack5',
testCommand: 'lerna run test:webpack5 --stream --scope webpack-plugin-build-statistics'
};
const rollup = {
directoryName: 'rollup-plugin',
testCommand: 'lerna run test --stream --scope rollup-plugin-build-statistics'
};
runIntegrationTest(webpack5);
runIntegrationTest(webpack4);
runIntegrationTest(rollup);