Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
fix(plugin-runner-jest): Prepare plugin to deal with projects that ha…
Browse files Browse the repository at this point in the history
…s more than one projects (#94)
  • Loading branch information
jonatasemidio authored Sep 20, 2022
1 parent 4b772a5 commit c94f1ae
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Handle multiple projects sharing the same config, when one of the projects contains Jest Projects. 1`] = `
Object {
"collectCoverage": true,
"projects": Array [
Object {
"rootDir": "/test_path",
"roots": Array [
"<rootDir>/foo",
],
"testEnvironment": "jsdom",
},
Object {
"name": "project_1",
"rootDir": "/test_path/test",
},
Object {
"name": "project_2",
"rootDir": "/test_path/test",
},
],
"rootDir": "/test_path",
}
`;

exports[`Handle project that contains Jest Projects. 1`] = `
Object {
"projects": Array [
Object {
"name": "project_1",
},
Object {
"name": "project_2",
},
],
"rootDir": "/test_path/test",
"roots": Array [
"<rootDir>/",
],
"testEnvironment": "node",
}
`;

exports[`Handles multiple projects sharing the same config 1`] = `
Object {
"collectCoverage": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testEnvironment: 'node',
projects: [
{name: "project_1"}, {name: "project_2"}
]
};
29 changes: 29 additions & 0 deletions packages/plugin-runner-jest/__tests__/getConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,32 @@ test('Handles multiple projects sharing the same config and one having different

expect(replaceTestPath(jestConfig, cwd)).toMatchSnapshot();
});

test('Handle multiple projects sharing the same config, when one of the projects contains Jest Projects.', async () => {
const cwd = await initFixture('basic');
const { context } = await createBatchContext<JestRunnerOptions>(
{
foo: { configFile: 'jest.config.js' },
test: { configFile: '{{projectDir}}/jest.projects.config.js' }
},
{ cwd, schema: require('../src/schema.json') }
);

const jestConfig = await getConfig(context);

expect(replaceTestPath(jestConfig, cwd)).toMatchSnapshot();
});

test('Handle project that contains Jest Projects.', async () => {
const cwd = await initFixture('basic');
const { context } = await createBatchContext<JestRunnerOptions>(
{
test: { configFile: '{{projectDir}}/jest.projects.config.js' }
},
{ cwd, schema: require('../src/schema.json') }
);

const jestConfig = await getConfig(context);

expect(replaceTestPath(jestConfig, cwd)).toMatchSnapshot();
});
14 changes: 13 additions & 1 deletion packages/plugin-runner-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ export async function getConfig(ctx: Context<JestRunnerOptions>) {
}

if (isMultipleConfigs && jestConfig.projects) {
jestConfig.projects.push(projectConfig as Config.ProjectConfig);
if (projectConfig.projects && projectConfig.projects.length > 0) {
const newProjects = projectConfig.projects as Config.ProjectConfig[];

newProjects.forEach(project => {
if (projectConfig.rootDir) {
project.rootDir = projectConfig.rootDir;
}
});

jestConfig.projects.push(...newProjects);
} else {
jestConfig.projects.push(projectConfig as Config.ProjectConfig);
}
} else {
Object.assign(jestConfig, projectConfig);
}
Expand Down

0 comments on commit c94f1ae

Please sign in to comment.