From 259d11b3ce6ec5e779e48d8e4e24575da4cff8b6 Mon Sep 17 00:00:00 2001 From: David Goss Date: Sun, 21 Apr 2024 08:19:28 +0100 Subject: [PATCH] add a test and github workflows (#7) --- .github/workflows/release-github.yaml | 18 ++++++++++++++++ .github/workflows/release-npm.yaml | 22 ++++++++++++++++++++ .github/workflows/test.yaml | 23 ++++++++++++++++++++ CHANGELOG.md | 4 +++- package-lock.json | 30 ++++++++++++++++++++++++++- package.json | 9 +++++++- validation.test.mjs | 25 ++++++++++++++++++++++ 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release-github.yaml create mode 100644 .github/workflows/release-npm.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 validation.test.mjs diff --git a/.github/workflows/release-github.yaml b/.github/workflows/release-github.yaml new file mode 100644 index 0000000..8030e41 --- /dev/null +++ b/.github/workflows/release-github.yaml @@ -0,0 +1,18 @@ +name: Release GitHub + +on: + push: + branches: [release/*] + +jobs: + create-github-release: + name: Create GitHub Release and Git tag + runs-on: ubuntu-latest + environment: Release + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: cucumber/action-create-github-release@v1.1.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-npm.yaml b/.github/workflows/release-npm.yaml new file mode 100644 index 0000000..1e00624 --- /dev/null +++ b/.github/workflows/release-npm.yaml @@ -0,0 +1,22 @@ +name: Release NPM + +on: + push: + branches: [release/*] + +jobs: + publish-npm: + name: Publish NPM module + runs-on: ubuntu-latest + environment: Release + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: package-lock.json + - run: npm install-test + - uses: cucumber/action-publish-npm@v1.1.1 + with: + npm-token: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..77e89e2 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,23 @@ +name: test + +on: + push: + branches: + - main + - renovate/** + pull_request: + branches: + - main + workflow_call: + +jobs: + test-javascript: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: package-lock.json + - run: npm install-test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a13f945..6136edd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +- Add tests and workflows ([#7](https://github.com/cucumber/cucumber-json-schema/pull/7)) ## [0.1.0] - 2024-04-18 ### Added -- Initial-release +- Initial release [Unreleased]: https://github.com/cucumber/cucumber-json-schema/compare/v0.1.0...HEAD [0.1.0]: https://github.com/cucumber/html-formatter/compare/8d0dcd7300b187348157e8ac9e01d45b066dcd1a...v0.1.0 diff --git a/package-lock.json b/package-lock.json index 22642e0..64c5724 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,35 @@ "": { "name": "@cucumber/json-schema", "version": "0.1.0", - "license": "MIT" + "license": "MIT", + "devDependencies": { + "@types/node": "^20.12.7", + "jsonschema": "^1.4.1" + } + }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/jsonschema": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.4.1.tgz", + "integrity": "sha512-S6cATIPVv1z0IlxdN+zUk5EPjkGCdnhN4wVSBlvoUO1tOLJootbo9CquNJmbIh4yikWHiUedhRYrNPn1arpEmQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true } } } diff --git a/package.json b/package.json index baec48b..5f63667 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,12 @@ "license": "MIT", "files": [ "schemas" - ] + ], + "devDependencies": { + "@types/node": "^20.12.7", + "jsonschema": "^1.4.1" + }, + "scripts": { + "test": "node ./validation.test.mjs" + } } diff --git a/validation.test.mjs b/validation.test.mjs new file mode 100644 index 0000000..a5b5e80 --- /dev/null +++ b/validation.test.mjs @@ -0,0 +1,25 @@ +import {equal} from 'node:assert/strict' +import {readFileSync} from 'node:fs' +import {describe, it} from 'node:test' +import {Validator} from 'jsonschema' + +const FILENAMES = [ + 'behave.json', + 'canonical.json', + 'cucumber-js.json', + 'cucumber-jvm.json', + 'cucumber-ruby.json', +] + +describe('schema validation', () => { + const validator = new Validator() + + FILENAMES.forEach(filename => { + it(filename, async () => { + const schema = JSON.parse(readFileSync('./schemas/' + filename, {encoding: 'utf-8'})) + const metaSchema = await fetch(schema['$schema']).then(response => response.json()) + const result = validator.validate(schema, metaSchema) + equal(result.valid, true) + }) + }) +}) \ No newline at end of file