Skip to content
Open
Show file tree
Hide file tree
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
70 changes: 70 additions & 0 deletions test/fixtures/test426/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: Validate tests and build npm package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
# Fetch all to count number of commits and compute pkg version
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: lts/*
cache: npm
- name: Install dependencies
run: npm ci
- name: Build npm package
run: node scripts/build-npm-package.js
- name: Check that JSON files match their TypeScript types
run: node scripts/check-types.js
- name: Pack npm package
run: mkdir -p dist && npm pack ./npm-package --pack-destination dist
- name: Upload package tarball
uses: actions/upload-artifact@v7
with:
name: npm-package
path: dist/*.tgz
if-no-files-found: error
retention-days: 7

publish:
name: Publish to npm
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && github.repository == 'tc39/source-map-tests'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # for npm trusted publishing
concurrency:
group: npm-publish
cancel-in-progress: false
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: lts/*
registry-url: https://registry.npmjs.org
- name: Build npm package
run: node scripts/build-npm-package.js
- name: Publish
run: |
name=$(node -p "require('./npm-package/package.json').name")
version=$(node -p "require('./npm-package/package.json').version")
if [ -n "$(npm view "$name@$version" version 2>/dev/null)" ]; then
echo "$name@$version is already published, skipping."
else
npm publish ./npm-package --access public
fi
6 changes: 6 additions & 0 deletions test/fixtures/test426/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
npm-package/*
!npm-package/README.md
!npm-package/package.template.json
!npm-package/types/
node_modules/
.tmp/
39 changes: 39 additions & 0 deletions test/fixtures/test426/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,42 @@ More information about running Chrome Devtools without building Chromium can be

Follow the [running Node.js tests guide](https://github.com/nodejs/node/blob/main/BUILDING.md#running-tests) to build Node.js and run tests locally.
Read more about running the source map tests at [here](https://github.com/nodejs/node/tree/main/test/test426).

## npm package

The test cases are published to npm as [`@tc39/source-map-tests`](https://www.npmjs.com/package/@tc39/source-map-tests), so that source map implementations can run them in their own test suites. A new version is published for every commit to `main`.

```sh
npm install --save-dev --save-exact @tc39/source-map-tests
```

### Usage

`@tc39/source-map-tests/suites.json` lists the test suites:

```json
{
"suites": [
{ "kind": "interpreting", "file": "interpreting/source-map-spec.json" },
{ "kind": "decoding", "file": "decoding/scopes.json" }
]
}
```

There are two types of test suites: `interpreting` and `decoding`:
- **interpreting** provided a source map to apply to a generated file, together with some actions to perform through it to check that it has been applied correctly.
- **decoding** suites check that a source map is correctly decoded into a [Decoded Source Map Record](https://tc39.es/ecma426/#decoded-source-map-record).

### TypeScript

The package's root exports the types of the JSON files:

```ts
import type { InterpretingSuite, DecodingSuite, TestAction } from "@tc39/source-map-tests";
```

With TypeScript 7.1 or later, you can load type definitions for the various suites by adding `"types": ["@tc39/source-map-tests"]` to your `tsconfig.json`. Imported JSON modules then will be typed appropriately:
```ts
import spec from "@tc39/source-map-tests/interpreting/source-map-spec.json" with { type: "json" };
spec.tests[0].testActions; // TestAction[]
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sections": [{
"offset": {
"line": 0,
"column": 0,
"column": 0
},
"map": {
"version": 3,
Expand All @@ -16,7 +16,7 @@
}, {
"offset": {
"line": 1,
"column": 0,
"column": 0
},
"map": {
"version": 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"file": "app.js",
"sources": [],
"mappings": [],
"mappings": []
}
4 changes: 2 additions & 2 deletions test/fixtures/test426/decoding/debug-id/debug-id-index.map
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"sections": [{
"offset": {
"line": 0,
"column": 0,
"column": 0
},
"map": {
"version": 3,
Expand All @@ -17,7 +17,7 @@
}, {
"offset": {
"line": 1,
"column": 0,
"column": 0
},
"map": {
"version": 3,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test426/decoding/debug-id/debug-id.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/// <reference path="../source-map-record.d.ts" />

interface SourceMapRecord {
debugId: string|null;
debugId?: string|null;
}
5 changes: 5 additions & 0 deletions test/fixtures/test426/npm-package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @tc39/source-map-tests

Cross-implementation test cases for the [ECMA-426 source map specification](https://tc39.es/ecma426/).

See the [tc39/source-map-tests README](https://github.com/tc39/source-map-tests#npm-package) for the package contents and usage.
26 changes: 26 additions & 0 deletions test/fixtures/test426/npm-package/package.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@tc39/source-map-tests",
"version": "X.X.X",
"description": "Cross-implementation test cases for the ECMA-426 source map specification",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git+https://github.com/tc39/source-map-tests.git"
},
"homepage": "https://github.com/tc39/source-map-tests#readme",
"bugs": "https://github.com/tc39/source-map-tests/issues",
"keywords": [
"source-map",
"sourcemap",
"ecma-426",
"test-suite",
"tests"
],
"files": [
"suites.json",
"interpreting/",
"decoding/",
"types/",
"LICENSE.md"
]
}
2 changes: 2 additions & 0 deletions test/fixtures/test426/npm-package/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="./modules.d.ts" />
export * from "./types.js";
14 changes: 14 additions & 0 deletions test/fixtures/test426/npm-package/types/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare module "@tc39/source-map-tests/suites*.json" with { type: "json" } {
const index: import("./types.js").SuitesIndex;
export default index;
}

declare module "@tc39/source-map-tests/interpreting/*.json" with { type: "json" } {
const suite: import("./types.js").InterpretingSuite;
export default suite;
}

declare module "@tc39/source-map-tests/decoding/*.json" with { type: "json" } {
const suite: import("./types.js").DecodingSuite;
export default suite;
}
90 changes: 90 additions & 0 deletions test/fixtures/test426/npm-package/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Types for the JSON files in this package.
*
* All paths are relative to the package root.
*/

/** The format of `suites.json`. */
export interface SuitesIndex {
suites: SuiteInfo[];
}

export type SuiteInfo =
| { kind: "interpreting"; file: string }
| { kind: "decoding"; file: string };

/** A file from the test suite, with its contents inlined. */
export interface TestFile {
path: string;
content: string;
}

/** The format of interpreting suite files (`interpreting/<name>.json`). */
export interface InterpretingSuite {
tests: InterpretingTest[];
}

export interface InterpretingTest {
name: string;
description: string;
sourceMapIsValid: boolean;
testActions: TestAction[];
/**
* The transpiled source that the source map refers to.
*/
baseFile: TestFile;
sourceMapFile: TestFile;
}

export type TestAction =
| CheckMappingAction
| CheckMappingTransitiveAction
| CheckIgnoreListAction;

export interface CheckMappingAction {
actionType: "checkMapping";
/** 0-based. */
generatedLine: number;
/** 0-based. */
generatedColumn: number;
originalSource: string | null;
/** 0-based. */
originalLine: number | null;
/** 0-based. */
originalColumn: number | null;
mappedName: string | null;
}

export interface CheckMappingTransitiveAction
extends Omit<CheckMappingAction, "actionType"> {
actionType: "checkMappingTransitive";
/** Source maps to apply after `sourceMapFile`, in order. */
intermediateMaps: TestFile[];
}

export interface CheckIgnoreListAction {
actionType: "checkIgnoreList";
/** Sources that must be in the ignore list. */
present: string[];
}

/** The format of decoding suite files (`decoding/<name>.json`). */
export interface DecodingSuite {
tests: DecodingTest[];
}

export interface DecodingTest {
name: string;
sourceMapFile: TestFile;
/**
* The expected Decoded Source Map Record, as JSON in the format described by
* `decoding/source-map-record.d.ts` (and extended by the proposal-specific
* `decoding/<suite>/<suite>.d.ts` files).
*/
goldenFile: TestFile;
/**
* Whether decoding this source map should optionally report an error
* (https://tc39.es/ecma426/#sec-optional-errors).
*/
optionalErrors: boolean;
}
Loading
Loading