Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
steps:
- name: Check out the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
- name: Set up with Node.js LTS
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
steps:
- name: Check out the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
- name: Set up with Node.js ${{ matrix.node-version }}
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "hed-tests"]
path = spec_tests/hed-tests
Comment thread
VisLab marked this conversation as resolved.
url = https://github.com/hed-standard/hed-tests.git
branch = main
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
### Changed

- Replaced action versions with hashes for security.
- The JSON spec tests now come from the [hed-tests](https://github.com/hed-standard/hed-tests)
repository, checked out as the git submodule `spec_tests/hed-tests` instead of the vendored
`spec_tests/javascriptTests.json`. Cases this validator does not pass yet are skipped by name
in `spec_tests/skippedTests.js`. Clone with `--recurse-submodules` or run
`git submodule update --init` before `npm run testSpecs`.

### Fixed

Expand All @@ -16,7 +21,7 @@

### Added

- `BidsWebAccessor` — a new browser-compatible BIDS file accessor that
- `BidsWebAccessor` — a new browser-compatible BIDS file accessor that
reads dataset files from browser `File` objects provided via an
`<input webkitdirectory>` element or drag-and-drop upload. Schema loading is
performed via remote HTTPS fetching. This enables in-browser BIDS/HED
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ main()
The `main` branch is now the default branch. All changes to the repository should
be done as PRs (pull requests) to the `main` branch.

### Running the tests

The JSON spec tests in `spec_tests/` read the [hed-tests](https://github.com/hed-standard/hed-tests)
suite from the git submodule `spec_tests/hed-tests`, so check it out before running them:

```code
git clone --recurse-submodules https://github.com/hed-standard/hed-javascript
cd hed-javascript
npm install
npm test # unit tests in tests/
npm run testSpecs # hed-tests JSON suite in spec_tests/
```

In an existing clone, `git submodule update --init` fetches the submodule. See
`spec_tests/README.md` for how the suite is run and how failing cases are skipped.

### Running the browser locally

The browser app has moved to the [hed-web](https://github.com/hed-standard/hed-web) repository.
Expand Down
13 changes: 7 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ module.exports = {
'^.+\\.(js|jsx)$': 'babel-jest',
},
transformIgnorePatterns: ['/node_modules/(?!unicode-name|semver)'],
testPathIgnorePatterns: ['node_modules/', '<rootDir>/types/test.ts', '<rootDir>/browser/'],
testPathIgnorePatterns: [
'node_modules/',
'<rootDir>/types/test.ts',
'<rootDir>/browser/',
'<rootDir>/spec_tests/hed-tests/',
],
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
collectCoverageFrom: [
'src/**/*.js',
'!src/**/*.spec.js',
'!src/**/*.test.js',
],
collectCoverageFrom: ['src/**/*.js', '!src/**/*.spec.js', '!src/**/*.test.js'],
coveragePathIgnorePatterns: [
'/node_modules/',
'/tests/',
Expand Down
69 changes: 58 additions & 11 deletions spec_tests/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
# HED spec tests

This directory contains the HED specification-level test suite.
This directory runs the official HED JSON test suite from the
[hed-tests](https://github.com/hed-standard/hed-tests) repository against this validator.

## Running tests
## Getting the test data

Run the spec tests using the npm script:
The suite lives in the git submodule `spec_tests/hed-tests`, pinned to a specific hed-tests
commit. It is empty in a plain clone until you fetch it:

```powershell
npm run testSpecs
git submodule update --init
```

This is equivalent to:
or clone with `git clone --recurse-submodules`. The runner fails with a message pointing here if
the submodule is missing.

## Running the tests

```powershell
npx jest --testPathPatterns='spec_tests/'
npm run testSpecs
```

## Test files
This is equivalent to `npx jest --testPathPatterns='/spec_tests/'`.

## Files

- **hedTests.spec.js** - the runner. Reads
`hed-tests/json_test_data/validation_tests.json` and runs every case's string, sidecar,
events and sidecar+events sub-tests through the BIDS validation entry points. A failing case
passes when one of its `error_code` or `alt_codes` is among the errors returned (among the
warnings, with no errors, when the case has `warning: true`). A passing case passes when no
errors are returned (and no warnings when `warning: true`).
- **skippedTests.js** - cases this validator does not pass yet, keyed by test case name with a
one-line reason. Each listed case is reported as skipped in the jest summary. Remove the entry
once the case passes.
- **hed-tests/** - the submodule. Do not edit files inside it; changes to the test suite go to
the hed-tests repository.

## Schema loading

Cases name schemas by version string (`8.4.0`, `ts:testconflict_2.1.0`, ...). Following the
convention in `hed-tests/json_test_data/test_schemas/README.md`, the runner resolves each version
string against `hed-tests/json_test_data/test_schemas/hedxml/` by cache-convention file name
(`HED<version>.xml` or `HED_<library>_<version>.xml`) when such a file exists, and otherwise
against the schemas bundled in `src/data/schemas/`. The test-only libraries (`testconflict`,
`testclash`, `testminimal`, `testaux`) and the vendored 8.5.0 prerelease therefore need no
network access. When building the schemas for a case throws, that issue is the result of every
sub-test of the case, which is how the SCHEMA_LOAD_FAILED cases are checked.

- **jsonTests.spec.js** — The main spec test suite that runs HED validation tests against test cases defined in `javascriptTests.json`. It validates parser behavior, BIDS support, and schema compliance using a comprehensive set of test vectors.
## Schema tests are not run

hed-tests also ships `schema_tests.json`, which checks that validators detect errors in HED
schema files themselves (the cases are mediawiki schema source text). hed-javascript assumes the
schemas it loads are valid and does not implement schema validation, so that file is skipped as a
block in `hedTests.spec.js` and is not part of this validator's conformance target.

## Updating the pin

```powershell
git -C spec_tests/hed-tests fetch origin
git -C spec_tests/hed-tests checkout <commit-or-origin/main>
npm run testSpecs
```

- **javascriptTests.json** — Data file containing the test cases used by `jsonTests.spec.js`. Includes test scenarios for tag parsing, definition validation, BIDS file validation, and error handling.
Add any newly failing case to `skippedTests.js` with a reason (or fix it), then commit the
submodule pointer together with the skip-list change.

## About spec tests
## Debugging one case

Spec tests validate the validator against the HED specification and ensure that all validator behavior is correct according to the spec. These are distinct from unit tests in `tests/` which test individual modules and functions.
At the top of `hedTests.spec.js`, set `runAll` to `false` and put the error code and case names
in `runMap`, or keep `runAll` and list cases in `skipMap`. `runOnly` restricts the sub-test kinds
(`stringPass`, `stringFail`, `sidecarPass`, `sidecarFail`, `eventsPass`, `eventsFail`,
`comboPass`, `comboFail`).
1 change: 1 addition & 0 deletions spec_tests/hed-tests
Submodule hed-tests added at 183c23
Loading
Loading