forked from microsoft/playwright-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
39 lines (37 loc) · 1.53 KB
/
jest.config.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
/* ---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const path = require('path');
const {GlobSync} = require('glob');
const projects = GlobSync('./packages/*/jest.config.js')
.found
.flatMap(filePath => flattenProjects(require(filePath), path.resolve(__dirname, path.dirname(filePath))));
module.exports = {projects};
function flattenProjects(project, baseDir) {
if (project.preset) {
const preset = resolvePreset(project.preset, baseDir);
delete project.preset;
for (const [key, value] of Object.entries(preset)) {
if (key in project)
continue;
project[key] = value;
}
}
if (!project.rootDir)
project.rootDir = baseDir;
if (!project.displayName)
project.displayName = path.basename(baseDir);
const {projects} = project;
if (!projects)
return [project];
delete project.projects;
return projects.flatMap(overrides => flattenProjects({...project, ...overrides}), baseDir);
}
function resolvePreset(name, baseDir) {
const presetPath = name.startsWith('.') ? name : path.join(name, 'jest-preset');
const resolvedPreset = require.resolve(presetPath, {baseDir, extensions: ['.js', '.json']});
const preset = require(resolvedPreset);
delete require.cache[resolvedPreset];
return preset;
}