-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjest.instrumentations.setup.js
53 lines (48 loc) · 1.85 KB
/
jest.instrumentations.setup.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
53
require('jest-json');
require('jest-chain');
const { instrumentationsVersionManager } = require('./test/helpers/InstrumentationsVersionManager');
const fs = require('fs');
const {
compareVersions,
loadPackageVersionsFromBackup,
} = require('./scripts/tested-versions-file-utils');
const runtimeVersion = parseInt(process.version.slice(1).split('.')[0]);
const oldEnv = Object.assign({}, process.env);
beforeEach(() => {
process.env = { ...oldEnv };
});
afterEach(() => {
process.env = { ...oldEnv };
});
beforeAll(() => {
global.console = require('console');
require('console-stamp')(global.console);
});
afterAll(() => {
console.info('Starting afterAll...');
if (process.env.DISABLE_SUPPORTED_VERSIONS_UPDATE?.toLowerCase() === 'true') {
console.info('DISABLE_SUPPORTED_VERSIONS_UPDATE is set to true, skipping post-test update.');
} else {
const versions = instrumentationsVersionManager.getInstrumentationsVersions();
console.info('Adding tested versions', JSON.stringify(versions));
const versions_keys = Object.keys(versions);
if (versions_keys.length) {
versions_keys.forEach((pkg) => {
// updated supported versions file
const testedVersionFolder = `./src/instrumentations/${pkg}/tested_versions`;
const testVersionsFile = `${testedVersionFolder}/${runtimeVersion}/${pkg}`;
fs.mkdirSync(testedVersionFolder, { recursive: true });
const versionStrings = versions[pkg].unsupported
.map((v) => `!${v}`)
.concat(versions[pkg].supported)
.concat(loadPackageVersionsFromBackup(pkg))
.sort(compareVersions)
.join('\n');
fs.writeFileSync(testVersionsFile, versionStrings);
console.info('Finish afterAll, supported version files were updated.');
});
} else {
console.info('Finish afterAll, no versions to update.');
}
}
});