Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use process.cwd as config.rootDir fallback #4587

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions integration-tests/__tests__/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ test('works with jsdom testEnvironmentOptions config JSON', () => {
expect(result.status).toBe(0);
expect(stderr).toMatch('found userAgent Agent/007');
});

test('rootDir should be correct if config not in the root folder', () => {
const {status, stderr} = runJest('config_not_in_root_and_rootDir', [
'--config=setup/config.json',
]);

expect(status).toBe(0);
expect(stderr).toMatch('PASS');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('assertion is correct', () => {
expect(true).toBe(true);
});
5 changes: 5 additions & 0 deletions integration_tests/config_not_in_root_and_rootDir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"setupTestFrameworkScriptFile": "<rootDir>/setup/setup.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 40 * 1000;
4 changes: 2 additions & 2 deletions packages/jest-config/src/read_config_file_and_set_root_dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default (configPath: Path): InitialOptions => {
);
}
} else {
// If rootDir is not there, we'll set it to this file's __dirname
configObject.rootDir = path.dirname(configPath);
// If rootDir is not there, we'll set it to cwd
configObject.rootDir = process.cwd();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the correct change - from what I can gather it looks at the filename now to support projects.

I'm not really sure what the correct behavior should be. I'm leading towards using cwd and requiring rootDir in the config of nested projects.

}

return configObject;
Expand Down