diff --git a/.github/workflows/test-javascript.yml b/.github/workflows/test-javascript.yml index 0348f9b1..d63793eb 100644 --- a/.github/workflows/test-javascript.yml +++ b/.github/workflows/test-javascript.yml @@ -27,7 +27,7 @@ jobs: matrix: os: - ubuntu-latest - node-version: ["20.x", "22.x", "24.x"] + node-version: ["22.x", "24.x", "26.x"] include: - os: windows-latest node-version: "22.x" diff --git a/CHANGELOG.md b/CHANGELOG.md index 61913df9..69eaa5d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +- [JavaScript] BREAKING CHANGE: Switch to ESM ([#173](https://github.com/cucumber/query/pull/173)) ## [15.0.1] - 2026-01-22 ### Fixed diff --git a/javascript/.mocharc.json b/javascript/.mocharc.json index dc536371..484e010f 100644 --- a/javascript/.mocharc.json +++ b/javascript/.mocharc.json @@ -1,5 +1,5 @@ { - "require": ["ts-node/register"], + "node-option": ["loader=ts-node/esm"], "extension": ["ts"], "recursive": true, "spec": ["src/**/*.spec.*"], diff --git a/javascript/package.json b/javascript/package.json index 37745751..e33ec385 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -2,7 +2,7 @@ "name": "@cucumber/query", "version": "15.0.1", "description": "Cucumber Query - query messages", - "type": "commonjs", + "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { @@ -10,6 +10,7 @@ "clean": "rm -rf dist", "fix": "biome check --fix --error-on-warnings", "lint": "biome check --error-on-warnings", + "postbuild": "node -e \"require('.')\"", "test": "mocha", "prepublishOnly": "tsc -p tsconfig.build.json" }, diff --git a/javascript/src/Query.spec.ts b/javascript/src/Query.spec.ts index 86604b66..d5bbdcbd 100644 --- a/javascript/src/Query.spec.ts +++ b/javascript/src/Query.spec.ts @@ -4,8 +4,8 @@ import path from 'node:path' import type { Envelope, TestCaseStarted } from '@cucumber/messages' -import type { Lineage } from './Lineage' -import Query from './Query' +import type { Lineage } from './Lineage.js' +import Query from './Query.js' describe('Query', () => { let cucumberQuery: Query @@ -91,7 +91,7 @@ describe('Query', () => { describe('#findLineageBy', () => { it('returns correct lineage for a minimal scenario', async () => { const envelopes: ReadonlyArray = ( - await fs.readFile(path.join(__dirname, '../../testdata/src/minimal.ndjson'), { + await fs.readFile(path.join(import.meta.dirname, '../../testdata/src/minimal.ndjson'), { encoding: 'utf-8', }) ) @@ -116,9 +116,12 @@ describe('Query', () => { it('returns correct lineage for a pickle from an examples table', async () => { const envelopes: ReadonlyArray = ( - await fs.readFile(path.join(__dirname, '../../testdata/src/examples-tables.ndjson'), { - encoding: 'utf-8', - }) + await fs.readFile( + path.join(import.meta.dirname, '../../testdata/src/examples-tables.ndjson'), + { + encoding: 'utf-8', + } + ) ) .split('\n') .filter((line) => !!line) @@ -147,9 +150,12 @@ describe('Query', () => { it('returns correct lineage for a pickle with background-derived steps', async () => { const envelopes: ReadonlyArray = ( - await fs.readFile(path.join(__dirname, '../../testdata/src/rules-backgrounds.ndjson'), { - encoding: 'utf-8', - }) + await fs.readFile( + path.join(import.meta.dirname, '../../testdata/src/rules-backgrounds.ndjson'), + { + encoding: 'utf-8', + } + ) ) .split('\n') .filter((line) => !!line) diff --git a/javascript/src/Query.ts b/javascript/src/Query.ts index 3f08c088..2cfb38e2 100644 --- a/javascript/src/Query.ts +++ b/javascript/src/Query.ts @@ -32,8 +32,8 @@ import { import { ArrayMultimap } from '@teppeis/multimaps' import sortBy from 'lodash.sortby' -import { assert, statusOrdinal } from './helpers' -import type { Lineage } from './Lineage' +import { assert, statusOrdinal } from './helpers.js' +import type { Lineage } from './Lineage.js' export default class Query { private meta: Meta diff --git a/javascript/src/acceptance.spec.ts b/javascript/src/acceptance.spec.ts index 93421afb..20738fd4 100644 --- a/javascript/src/acceptance.spec.ts +++ b/javascript/src/acceptance.spec.ts @@ -7,7 +7,7 @@ import { pipeline } from 'node:stream/promises' import { NdjsonToMessageStream } from '@cucumber/message-streams' import type { Envelope, Pickle } from '@cucumber/messages' -import Query from './Query' +import Query from './Query.js' const reversePickleComparator = (a: Pickle, b: Pickle): number => { if (a.uri !== b.uri) { @@ -21,15 +21,15 @@ const reversePickleComparator = (a: Pickle, b: Pickle): number => { describe('Acceptance Tests', async () => { const sources = [ - path.join(__dirname, '../../testdata/src/attachments.ndjson'), - path.join(__dirname, '../../testdata/src/empty.ndjson'), - path.join(__dirname, '../../testdata/src/global-hooks.ndjson'), - path.join(__dirname, '../../testdata/src/global-hooks-attachments.ndjson'), - path.join(__dirname, '../../testdata/src/hooks.ndjson'), - path.join(__dirname, '../../testdata/src/minimal.ndjson'), - path.join(__dirname, '../../testdata/src/rules.ndjson'), - path.join(__dirname, '../../testdata/src/examples-tables.ndjson'), - path.join(__dirname, '../../testdata/src/unknown-parameter-type.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/attachments.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/empty.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/global-hooks.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/global-hooks-attachments.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/hooks.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/minimal.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/rules.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/examples-tables.ndjson'), + path.join(import.meta.dirname, '../../testdata/src/unknown-parameter-type.ndjson'), ] const queries: Queries = { countMostSevereTestStepResultStatus: (query: Query) => @@ -316,7 +316,10 @@ describe('Acceptance Tests', async () => { const expectedResults = JSON.parse( fs.readFileSync( - path.join(__dirname, `../../testdata/src/${suiteName}.${methodName}.results.json`), + path.join( + import.meta.dirname, + `../../testdata/src/${suiteName}.${methodName}.results.json` + ), { encoding: 'utf-8', } diff --git a/javascript/src/index.ts b/javascript/src/index.ts index ce3ed4c2..2d188e32 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -1,5 +1,5 @@ -import Query from './Query' +import Query from './Query.js' -export * from './Lineage' +export * from './Lineage.js' export { Query }