Skip to content

Commit fb1166e

Browse files
committed
feat(cli): hard error the test runner if we don't have a test config and no package.json in the cwd
1 parent ce2f67e commit fb1166e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/cli/src/testing/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { setAreTestRunning, setTestLogger } from "./state.js";
1717

1818
const configPath = pathJoin(process.cwd(), "test/config.js");
19+
const packageJsonPath = pathJoin(process.cwd(), "package.json");
1920

2021
/**
2122
* @typedef {object} TestConfig
@@ -147,6 +148,13 @@ export async function testingLoadConfig(logger, flags) {
147148

148149
resolvedConfig.setup = config.setup ?? noop;
149150
resolvedConfig.teardown = config.teardown ?? noop;
151+
} else if (!existsSync(packageJsonPath)) {
152+
// If we can't resolve a test config, double check that the user executes the tests
153+
// from the project root. Always running tests from the project root has the least
154+
// surprises in the long run.
155+
throw new Error(
156+
`Make sure to start the tests from the project root, found '${process.cwd()}'. If you really need to run tests from this directory, create a 'package.json' in this directory.`,
157+
);
150158
}
151159

152160
// Initialize environment

0 commit comments

Comments
 (0)