Skip to content

fix(cucumber-runner): allow esm imports (#3805) #3806

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

Merged
Merged
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
13 changes: 10 additions & 3 deletions lib/runner/test-runners/cucumber.js
Original file line number Diff line number Diff line change
@@ -107,14 +107,21 @@ class CucumberSuite extends TestSuite {
}

createInitialRequires() {
const {options} = this.settings.test_runner;
const isESMEnable = options.enable_esm || this.argv['enable-esm'];
const importTypeArgument = isESMEnable ? '--import' : '--require';
const initialRequires = [
'--require', CucumberSuite.cucumberSetupFile
importTypeArgument, CucumberSuite.cucumberSetupFile
];

initialRequires.push(...this.buildArgvValue(['require', 'require-module']));
if (isESMEnable){
initialRequires.push(...this.buildArgvValue(['import']));
} else {
initialRequires.push(...this.buildArgvValue(['require', 'require-module']));
}

return this.allModulePaths.reduce((prev, spec) => {
prev.push('--require', spec);
prev.push(importTypeArgument, spec);

return prev;
}, initialRequires);
45 changes: 43 additions & 2 deletions test/src/runner/cucumber-integration/testCliArgs.js
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ describe('Cucumber cli arguments', function(){
assert.ok(cliArgs.includes('--no-strict'));
assert.ok(cliArgs.includes('--parallel'));
assert.strictEqual(cliArgs[cliArgs.indexOf('--parallel')+1], 3);
assert.ok(cliArgs.includes('--require'));
});

it('Cucumber cli arg --dry-run', function(){
@@ -90,7 +91,7 @@ describe('Cucumber cli arguments', function(){
assert.ok(cliArgs.includes('--dry-run'));
});

it('Cucumbr additional option --retries', function(){
it('Cucumber additional option --retries', function(){
const runner = new CucumberRunner({
test_runner: {
type: 'cucumber',
@@ -108,7 +109,7 @@ describe('Cucumber cli arguments', function(){
assert.ok(cliArgs.includes('--retry'));
});

it('Cucumbr additional options --retry and --format', function(){
it('Cucumber additional options --retry and --format', function(){
const runner = new CucumberRunner({
test_runner: {
type: 'cucumber',
@@ -129,4 +130,44 @@ describe('Cucumber cli arguments', function(){
assert.strictEqual(cliArgs[cliArgs.indexOf('--retry')+1], 3);
assert.strictEqual(cliArgs[cliArgs.indexOf('--format')+1], '@cucumber/pretty-formatter');
});

it('Cucumber cli arg --enable-esm', function(){
const runner = new CucumberRunner({
test_runner: {
type: 'cucumber',
options: {}
}
}, {
'enable-esm': true
}, {});

runner.createTestSuite({
modules: [path.join(__dirname, '../../../cucumber-integration-tests/sample_cucumber_tests/integration/testSample.js')],
modulePath: [path.join(__dirname, '../../../cucumber-integration-tests/sample_cucumber_tests/integration/testSample.js')]
});

assert.ok(cliArgs.includes('--import'));
assert.ok(!cliArgs.includes('--require'));
});

it('Cucumber options enable esm support', function(){
const runner = new CucumberRunner({
test_runner: {
type: 'cucumber',
options: {
enable_esm: true
}
}
}, {}, {});

const testModulePath = path.join(__dirname, '../../../cucumber-integration-tests/sample_cucumber_tests/integration/testSample.js');

runner.createTestSuite({
modules: [testModulePath],
modulePath: [testModulePath]
});

assert.ok(cliArgs.includes('--import'));
assert.ok(!cliArgs.includes('--require'));
});
});