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

temporarily revert ESM change #1647

Merged
merged 2 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,8 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

### Fixed

* Temporarily remove ESM changes due to impact on formatters

## [7.2.0] (2021-04-20)

### Added
Expand Down
1 change: 0 additions & 1 deletion dependency-lint.yml
Expand Up @@ -43,7 +43,6 @@ requiredModules:
- 'dist/**/*'
- 'lib/**/*'
- 'node_modules/**/*'
- 'src/importers.js'
- 'tmp/**/*'
root: '**/*.{js,ts}'
stripLoaders: false
Expand Down
16 changes: 0 additions & 16 deletions docs/cli.md
Expand Up @@ -81,22 +81,6 @@ You can pass in format options with `--format-options <JSON>`. The JSON string m

* Suggested use: add with profiles so you can define an object and use `JSON.stringify` instead of writing `JSON` manually.

## ES Modules (experimental) (Node.js 12+)

You can optionally write your support code (steps, hooks, etc) with native ES modules syntax - i.e. using `import` and `export` statements without transpiling.

To enable this, run with the `--esm` flag.

This will also expand the default glob for support files to include the `.mjs` file extension.

As well as support code, these things can also be in ES modules syntax:

- Custom formatters
- Custom snippets
- Your `cucumber.js` config file

You can use ES modules selectively/incrementally - the module loading strategy that the `--esm` flag activates supports both ES modules and CommonJS.

## Colors

Colors can be disabled with `--format-options '{"colorsEnabled": false}'`
Expand Down
80 changes: 0 additions & 80 deletions features/esm.feature

This file was deleted.

14 changes: 1 addition & 13 deletions features/support/hooks.ts
Expand Up @@ -13,7 +13,7 @@ Before('@debug', function (this: World) {
this.debug = true
})

Before('@spawn or @esm', function (this: World) {
Before('@spawn', function (this: World) {
this.spawn = true
})

Expand Down Expand Up @@ -43,18 +43,6 @@ Before(function (
this.localExecutablePath = path.join(projectPath, 'bin', 'cucumber-js')
})

Before('@esm', function (this: World) {
const [majorVersion] = process.versions.node.split('.')
if (Number(majorVersion) < 12) {
return 'skipped'
}
fsExtra.writeJSONSync(path.join(this.tmpDir, 'package.json'), {
name: 'feature-test-pickle',
type: 'module',
})
return undefined
})

Before('@global-install', function (this: World) {
const tmpObject = tmp.dirSync({ unsafeCleanup: true })

Expand Down
7 changes: 2 additions & 5 deletions package.json
Expand Up @@ -163,10 +163,6 @@
"lib": "./lib"
},
"main": "./lib/index.js",
"exports": {
"import": "./lib/wrapper.mjs",
"require": "./lib/index.js"
},
"types": "./lib/index.d.ts",
"engines": {
"node": ">=10"
Expand All @@ -186,6 +182,7 @@
"cli-table3": "^0.6.0",
"colors": "^1.4.0",
"commander": "^7.0.0",
"create-require": "^1.1.1",
"duration": "^0.2.2",
"durations": "^3.4.2",
"figures": "^3.2.0",
Expand Down Expand Up @@ -260,7 +257,7 @@
"typescript": "4.2.3"
},
"scripts": {
"build-local": "tsc -p tsconfig.node.json && cp src/importers.js lib/ && cp src/wrapper.mjs lib/",
"build-local": "tsc -p tsconfig.node.json",
"cck-test": "mocha 'compatibility/**/*_spec.ts'",
"feature-test": "node ./bin/cucumber-js",
"html-formatter": "node ./bin/cucumber-js --profile htmlFormatter",
Expand Down
2 changes: 0 additions & 2 deletions src/cli/argv_parser.ts
Expand Up @@ -22,7 +22,6 @@ export interface IParsedArgvFormatOptions {
export interface IParsedArgvOptions {
backtrace: boolean
dryRun: boolean
esm: boolean
exit: boolean
failFast: boolean
format: string[]
Expand Down Expand Up @@ -113,7 +112,6 @@ const ArgvParser = {
'invoke formatters without executing steps',
false
)
.option('--esm', 'import support code via ES module imports', false)
.option(
'--exit',
'force shutdown of the event loop when the test run has finished: cucumber will call process.exit',
Expand Down
4 changes: 1 addition & 3 deletions src/cli/configuration_builder.ts
Expand Up @@ -19,7 +19,6 @@ export interface IConfigurationFormat {
}

export interface IConfiguration {
esm: boolean
featureDefaultLanguage: string
featurePaths: string[]
formats: IConfigurationFormat[]
Expand Down Expand Up @@ -81,11 +80,10 @@ export default class ConfigurationBuilder {
}
supportCodePaths = await this.expandPaths(
unexpandedSupportCodePaths,
this.options.esm ? '.@(js|mjs)' : '.js'
'.js'
)
}
return {
esm: this.options.esm,
featureDefaultLanguage: this.options.language,
featurePaths,
formats: this.getFormats(),
Expand Down
91 changes: 19 additions & 72 deletions src/cli/configuration_builder_spec.ts
Expand Up @@ -29,7 +29,6 @@ describe('Configuration', () => {

// Assert
expect(result).to.eql({
esm: false,
featureDefaultLanguage: 'en',
featurePaths: [],
formatOptions: {},
Expand Down Expand Up @@ -66,79 +65,27 @@ describe('Configuration', () => {
})

describe('path to a feature', () => {
describe('without esm', () => {
it('returns the appropriate feature and support code paths', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
const featurePath = path.join(cwd, relativeFeaturePath)
await fsExtra.outputFile(featurePath, '')
const supportCodePath = path.join(cwd, 'features', 'a.js')
await fsExtra.outputFile(supportCodePath, '')
const argv = baseArgv.concat([relativeFeaturePath])

// Act
const {
featurePaths,
pickleFilterOptions,
supportCodePaths,
} = await ConfigurationBuilder.build({ argv, cwd })

// Assert
expect(featurePaths).to.eql([featurePath])
expect(pickleFilterOptions.featurePaths).to.eql([relativeFeaturePath])
expect(supportCodePaths).to.eql([supportCodePath])
})
})
it('returns the appropriate feature and support code paths', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
const featurePath = path.join(cwd, relativeFeaturePath)
await fsExtra.outputFile(featurePath, '')
const supportCodePath = path.join(cwd, 'features', 'a.js')
await fsExtra.outputFile(supportCodePath, '')
const argv = baseArgv.concat([relativeFeaturePath])

describe('with esm and js support files', () => {
it('returns the appropriate feature and support code paths', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
const featurePath = path.join(cwd, relativeFeaturePath)
await fsExtra.outputFile(featurePath, '')
const supportCodePath = path.join(cwd, 'features', 'a.js')
await fsExtra.outputFile(supportCodePath, '')
const argv = baseArgv.concat([relativeFeaturePath, '--esm'])

// Act
const {
featurePaths,
pickleFilterOptions,
supportCodePaths,
} = await ConfigurationBuilder.build({ argv, cwd })

// Assert
expect(featurePaths).to.eql([featurePath])
expect(pickleFilterOptions.featurePaths).to.eql([relativeFeaturePath])
expect(supportCodePaths).to.eql([supportCodePath])
})
})
// Act
const {
featurePaths,
pickleFilterOptions,
supportCodePaths,
} = await ConfigurationBuilder.build({ argv, cwd })

describe('with esm and mjs support files', () => {
it('returns the appropriate feature and support code paths', async function () {
// Arrange
const cwd = await buildTestWorkingDirectory()
const relativeFeaturePath = path.join('features', 'a.feature')
const featurePath = path.join(cwd, relativeFeaturePath)
await fsExtra.outputFile(featurePath, '')
const supportCodePath = path.join(cwd, 'features', 'a.mjs')
await fsExtra.outputFile(supportCodePath, '')
const argv = baseArgv.concat([relativeFeaturePath, '--esm'])

// Act
const {
featurePaths,
pickleFilterOptions,
supportCodePaths,
} = await ConfigurationBuilder.build({ argv, cwd })

// Assert
expect(featurePaths).to.eql([featurePath])
expect(pickleFilterOptions.featurePaths).to.eql([relativeFeaturePath])
expect(supportCodePaths).to.eql([supportCodePath])
})
// Assert
expect(featurePaths).to.eql([featurePath])
expect(pickleFilterOptions.featurePaths).to.eql([relativeFeaturePath])
expect(supportCodePaths).to.eql([supportCodePath])
})
})

Expand Down
8 changes: 1 addition & 7 deletions src/cli/helpers.ts
Expand Up @@ -16,9 +16,6 @@ import TestCaseHookDefinition from '../models/test_case_hook_definition'
import TestRunHookDefinition from '../models/test_run_hook_definition'
import { builtinParameterTypes } from '../support_code_library_builder'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const importers = require('../importers')

const StepDefinitionPatternType =
messages.StepDefinition.StepDefinitionPattern.StepDefinitionPatternType

Expand All @@ -32,11 +29,8 @@ export async function getExpandedArgv({
cwd,
}: IGetExpandedArgvRequest): Promise<string[]> {
const { options } = ArgvParser.parse(argv)
const importer = options.esm ? importers.esm : importers.legacy
let fullArgv = argv
const profileArgv = await new ProfileLoader(cwd, importer).getArgv(
options.profile
)
const profileArgv = await new ProfileLoader(cwd).getArgv(options.profile)
if (profileArgv.length > 0) {
fullArgv = _.concat(argv.slice(0, 2), profileArgv, argv.slice(2))
}
Expand Down