Skip to content

load files mentioned in mocha config file #56

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions packages/mocha-runner/src/mocha-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,23 @@ class MochaRunner implements TestRunner {
require(mod);
}
}
if (mocha.options.files!== undefined) {
if (!(mocha.options.files instanceof Array)) {
mocha.options.files = [mocha.options.files];
}
for (let mod of mocha.options.files) {
const abs = fs.existsSync(mod) || fs.existsSync(mod + '.js');
if (abs) {
mod = path.resolve(mod);
}
mocha.addFile(mod);
}
}
return mocha;
}
async discoverTests(argv: parser.Arguments): Promise<DiscoveryResult> {
const mocha = this.createMochaInstance()
await mocha.loadFilesAsync();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this because I wanted to load pre test file first

const tests: Test[] = [];
const testSuites: TestSuite[] = [];

Expand Down Expand Up @@ -113,6 +126,7 @@ class MochaRunner implements TestRunner {
for (const filename of testFilesToProcessList) {
mocha.addFile(filename);
}
await mocha.loadFilesAsync();
const runnerWithResults: CustomRunner = mocha.run(() => {
testRunTask.resolve();
});
Expand Down