diff --git a/package-lock.json b/package-lock.json index 067b0ea160..5c0f0da6ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "@commitlint/cli": "=19.4.1", "@commitlint/config-conventional": "=19.4.1", "@types/benchmark": "^2.1.5", - "@types/chai": "^4.3.20", + "@types/chai": "^5.0.0", "@types/dedent": "=0.7.2", "@types/jsdom-global": "^3.0.7", "@types/mocha": "=10.0.9", @@ -31,7 +31,7 @@ "@typescript-eslint/parser": "=7.18.0", "babel-loader": "=9.1.3", "benchmark": "=2.1.4", - "chai": "^4.5.0", + "chai": "^5.1.1", "copyfiles": "=2.4.1", "core-js": "=3.38.1", "cross-env": "=7.0.3", @@ -8321,9 +8321,9 @@ } }, "node_modules/@types/chai": { - "version": "4.3.20", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.20.tgz", - "integrity": "sha512-/pC9HAB5I/xMlc5FP77qjCnI16ChlJfW0tGa0IUcFn38VJrTV6DeZ60NU5KZBtaOZqjdpwTWohz5HU1RrhiYxQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.0.0.tgz", + "integrity": "sha512-+DwhEHAaFPPdJ2ral3kNHFQXnTfscEEFsUxzD+d7nlcLrFK23JtNjH71RGasTcHb88b4vVi4mTyfpf8u2L8bdA==", "dev": true }, "node_modules/@types/connect": { @@ -10085,12 +10085,12 @@ "dev": true }, "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", "dev": true, "engines": { - "node": "*" + "node": ">=12" } }, "node_modules/ast-types-flow": { @@ -11203,21 +11203,19 @@ } }, "node_modules/chai": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz", - "integrity": "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/chai/-/chai-5.1.1.tgz", + "integrity": "sha512-pT1ZgP8rPNqUgieVaEY+ryQr6Q4HXNg8Ei9UnLUrjN4IA7dvQC5JB+/kxVcPNDHyBcc/26CXPkbNzq3qwrOEKA==", "dev": true, "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.3", - "deep-eql": "^4.1.3", - "get-func-name": "^2.0.2", - "loupe": "^2.3.6", - "pathval": "^1.1.1", - "type-detect": "^4.1.0" + "assertion-error": "^2.0.1", + "check-error": "^2.1.1", + "deep-eql": "^5.0.1", + "loupe": "^3.1.0", + "pathval": "^2.0.0" }, "engines": { - "node": ">=4" + "node": ">=12" } }, "node_modules/chalk": { @@ -11257,15 +11255,12 @@ "dev": true }, "node_modules/check-error": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", - "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.1.tgz", + "integrity": "sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==", "dev": true, - "dependencies": { - "get-func-name": "^2.0.2" - }, "engines": { - "node": "*" + "node": ">= 16" } }, "node_modules/check-types": { @@ -13737,13 +13732,10 @@ } }, "node_modules/deep-eql": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.4.tgz", - "integrity": "sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", + "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==", "dev": true, - "dependencies": { - "type-detect": "^4.0.0" - }, "engines": { "node": ">=6" } @@ -17212,15 +17204,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-func-name": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", - "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/get-intrinsic": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", @@ -26496,13 +26479,10 @@ } }, "node_modules/loupe": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", - "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", - "dev": true, - "dependencies": { - "get-func-name": "^2.0.1" - } + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.1.2.tgz", + "integrity": "sha512-23I4pFZHmAemUnz8WZXbYRSKYj801VDaNv9ETuMh7IrMc7VuVVSo+Z9iLE3ni30+U48iDWfi30d3twAXBYmnCg==", + "dev": true }, "node_modules/lower-case": { "version": "2.0.2", @@ -29162,12 +29142,12 @@ } }, "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.0.tgz", + "integrity": "sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==", "dev": true, "engines": { - "node": "*" + "node": ">= 14.16" } }, "node_modules/performance-now": { diff --git a/package.json b/package.json index 4ace6ac513..28b86c6775 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@commitlint/cli": "=19.4.1", "@commitlint/config-conventional": "=19.4.1", "@types/benchmark": "^2.1.5", - "@types/chai": "^4.3.20", + "@types/chai": "^5.0.0", "@types/dedent": "=0.7.2", "@types/jsdom-global": "^3.0.7", "@types/mocha": "=10.0.9", @@ -64,7 +64,7 @@ "@typescript-eslint/parser": "=7.18.0", "babel-loader": "=9.1.3", "benchmark": "=2.1.4", - "chai": "^4.5.0", + "chai": "^5.1.1", "copyfiles": "=2.4.1", "core-js": "=3.38.1", "cross-env": "=7.0.3", diff --git a/packages/apidom-parser-adapter-yaml-1-2/.eslintignore b/packages/apidom-parser-adapter-yaml-1-2/.eslintignore index 856320e627..23853b909a 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/.eslintignore +++ b/packages/apidom-parser-adapter-yaml-1-2/.eslintignore @@ -1,8 +1,8 @@ +/**/*.js +/**/*.mjs +/**/*.cjs /dist -/es -/cjs /types /config /.nyc_output /node_modules -/**/*.js diff --git a/packages/apidom-parser-adapter-yaml-1-2/.gitignore b/packages/apidom-parser-adapter-yaml-1-2/.gitignore index 33305ee872..d69d849689 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/.gitignore +++ b/packages/apidom-parser-adapter-yaml-1-2/.gitignore @@ -1,6 +1,7 @@ +/src/**/*.mjs +/src/**/*.cjs +/test/**/*.mjs /dist -/es -/cjs /types /wasm /NOTICE diff --git a/packages/apidom-parser-adapter-yaml-1-2/.mocharc.json b/packages/apidom-parser-adapter-yaml-1-2/.mocharc.json index e923c24114..6fc13fb712 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/.mocharc.json +++ b/packages/apidom-parser-adapter-yaml-1-2/.mocharc.json @@ -1,5 +1,7 @@ { "recursive": true, - "spec": "test/**/*.ts", - "file": ["test/mocha-bootstrap.cjs"] + "spec": "test/**/*.mjs", + "loader": "./test/wasm-loader.mjs", + "file": ["test/mocha-bootstrap.mjs"], + "ignore": ["test/perf/**/*.mjs"] } diff --git a/packages/apidom-parser-adapter-yaml-1-2/package.json b/packages/apidom-parser-adapter-yaml-1-2/package.json index d09bb12407..c9c82901f9 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/package.json +++ b/packages/apidom-parser-adapter-yaml-1-2/package.json @@ -8,27 +8,27 @@ }, "type": "module", "sideEffects": [ - "./es/lexical-analysis/browser-patch.mjs", - "./cjs/lexical-analysis/browser-patch.cjs" + "./src/lexical-analysis/browser-patch.mjs", + "./src/lexical-analysis/browser-patch.cjs" ], "unpkg": "./dist/apidom-parser-apdater-yaml-1-2.browser.min.js", - "main": "./cjs/adapter-node.cjs", + "main": "./src/adapter-node.cjs", "exports": { "types": "./types/dist.d.ts", "node": { - "import": "./es/adapter-node.mjs", - "require": "./cjs/adapter-node.cjs" + "import": "./src/adapter-node.mjs", + "require": "./src/adapter-node.cjs" }, "browser": { - "import": "./es/adapter-browser.mjs" + "import": "./src/adapter-browser.mjs" }, - "default": "./cjs/adapter-node.cjs" + "default": "./src/adapter-node.cjs" }, "types": "./types/dist.d.ts", "scripts": { "build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser", - "build:es": "npm run build:wasm && npm run build:wasm:copy && cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'", - "build:cjs": "npm run build:wasm && npm run build:wasm:copy && BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'", + "build:es": "npm run build:wasm && npm run build:wasm:copy && cross-env BABEL_ENV=es babel src --out-dir src --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'", + "build:cjs": "npm run build:wasm && npm run build:wasm:copy && BABEL_ENV=cjs babel src --out-dir src --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'", "build:umd:browser": "npm run build:wasm && npm run build:wasm:copy && cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress", "build:wasm": "node ../../scripts/file-exists.js ../../node_modules/tree-sitter-yaml/tree-sitter-yaml.wasm && exit 0 || cd ../../node_modules/tree-sitter-yaml && cross-env BABEL_ENV=cjs NODE_OPTIONS='-r core-js/stable @babel/register' tree-sitter generate --abi=13 ./grammar.js && tree-sitter build-wasm && node-gyp rebuild", "build:wasm:copy": "copyfiles -u 4 ../../node_modules/tree-sitter-yaml/tree-sitter-yaml.wasm wasm", @@ -37,10 +37,10 @@ "clean": "rimraf ./es ./cjs ./dist ./types", "typescript:check-types": "tsc --noEmit", "typescript:declaration": "tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js", - "test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha", - "perf": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/index.cjs", - "perf:lexical-analysis": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/lexical-analysis.cjs", - "perf:parse-syntactic-analysis-indirect": "cross-env NODE_ENV=test BABEL_ENV=cjs node ./test/perf/parse-syntactic-analysis-indirect.cjs", + "test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha", + "perf": "cross-env BABEL_ENV=es babel ./test/perf/index.ts --out-file ./test/perf/index.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/index.mjs", + "perf:lexical-analysis": "cross-env BABEL_ENV=es babel ./test/perf/lexical-analysis.ts --out-file ./test/perf/lexical-analysis.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/lexical-analysis.mjs", + "perf:parse-syntactic-analysis-indirect": "cross-env BABEL_ENV=es babel ./test/perf/parse-syntactic-analysis-indirect.ts --out-file ./test/perf/parse-syntactic-analysis-indirect.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/parse-syntactic-analysis-indirect.mjs", "prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .", "postpack": "rimraf NOTICE LICENSES" }, diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/.eslintrc b/packages/apidom-parser-adapter-yaml-1-2/test/.eslintrc index 85759a803c..60ef098f78 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/.eslintrc +++ b/packages/apidom-parser-adapter-yaml-1-2/test/.eslintrc @@ -24,15 +24,32 @@ "mocha/no-top-level-hooks": 2, "mocha/no-identical-title": 2, "mocha/no-nested-tests": 2, - "mocha/no-exclusive-tests": 2 - }, - "overrides": [{ - "files": ["mocha-bootstrap.cjs"], - "parserOptions": { - "sourceType": "script" - }, - "rules": { - "@typescript-eslint/no-var-requires": 0 - } - }] + "mocha/no-exclusive-tests": 2, + "import/no-relative-packages": 0, + "no-underscore-dangle": 0, + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "variable", + "format": ["camelCase", "PascalCase", "UPPER_CASE"], + "leadingUnderscore": "forbid" + }, + { + "selector": "variable", + "format": null, + "filter": { + "regex": "^__dirname$", + "match": true + } + }, + { + "selector": "variable", + "format": null, + "filter": { + "regex": "^__filename$", + "match": true + } + } + ] + } } diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/__snapshots__/adapter-browser.ts.snap b/packages/apidom-parser-adapter-yaml-1-2/test/__snapshots__/adapter-browser.mjs.snap similarity index 100% rename from packages/apidom-parser-adapter-yaml-1-2/test/__snapshots__/adapter-browser.ts.snap rename to packages/apidom-parser-adapter-yaml-1-2/test/__snapshots__/adapter-browser.mjs.snap diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts index ba4eae6c0b..cb96c3e39f 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-browser.ts @@ -1,5 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import { toValue, @@ -11,6 +12,7 @@ import { import * as adapter from '../src/adapter-browser'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-data.yaml')).toString(); describe('adapter-browser', function () { diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/__snapshots__/index.ts.snap b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/__snapshots__/index.mjs.snap similarity index 100% rename from packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/__snapshots__/index.ts.snap rename to packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/__snapshots__/index.mjs.snap diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts index 1f35dd5aa9..765411fefa 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts @@ -1,5 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import { YamlTagError } from '@swagger-api/apidom-ast'; import { @@ -12,6 +13,7 @@ import { import * as adapter from '../../src/adapter-node'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const spec = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'sample-data.yaml')).toString(); describe('adapter-node', function () { @@ -134,8 +136,8 @@ describe('adapter-node', function () { tagKind: 'Scalar', nodeCanonicalContent: undefined, }); - assert.include(error.tagPosition.start, { type: 'point', row: 0, column: 6, char: 6 }); - assert.include(error.tagPosition.end, { type: 'point', row: 0, column: 18, char: 18 }); + assert.include(error.tagPosition?.start, { type: 'point', row: 0, column: 6, char: 6 }); + assert.include(error.tagPosition?.end, { type: 'point', row: 0, column: 18, char: 18 }); } }); }); @@ -156,8 +158,8 @@ describe('adapter-node', function () { tagKind: 'Scalar', nodeCanonicalContent: 'value', }); - assert.include(error.tagPosition.start, { type: 'point', row: 0, column: 6, char: 6 }); - assert.include(error.tagPosition.end, { type: 'point', row: 0, column: 11, char: 11 }); + assert.include(error.tagPosition?.start, { type: 'point', row: 0, column: 6, char: 6 }); + assert.include(error.tagPosition?.end, { type: 'point', row: 0, column: 11, char: 11 }); } }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.cjs b/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.cjs deleted file mode 100644 index 7f0a200a6c..0000000000 --- a/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.cjs +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable */ - -require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); - -/** - * Configure snapshot testing. - */ -const chai = require('chai'); -const { jestSnapshotPlugin, addSerializer } = require('mocha-chai-jest-snapshot'); - -const jestApiDOMSerializer = require('../../../scripts/jest-serializer-apidom.cjs'); -const jestStringSerializer = require('../../../scripts/jest-serializer-string.cjs'); - -chai.use(jestSnapshotPlugin()); -addSerializer(jestApiDOMSerializer); -addSerializer(jestStringSerializer); - -/** - * JSDOM setup. - */ -require('jsdom-global')(); - -/** - * This loader is responsible for loading WASM files in node.js environment. - */ - -// WASM documents loader -const WASMLoader = (module, filename) => { - module.exports = filename; -}; - -// allow loading of WASM documents -require.extensions['.wasm'] = WASMLoader; diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.ts b/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.ts new file mode 100644 index 0000000000..051a3ad2fa --- /dev/null +++ b/packages/apidom-parser-adapter-yaml-1-2/test/mocha-bootstrap.ts @@ -0,0 +1,20 @@ +import * as chai from 'chai'; +import { jestSnapshotPlugin, addSerializer } from 'mocha-chai-jest-snapshot'; +import jsdomGlobal from 'jsdom-global'; + +// @ts-ignore +import * as jestApiDOMSerializer from '../../../scripts/jest-serializer-apidom'; +// @ts-ignore +import * as jestStringSerializer from '../../../scripts/jest-serializer-string'; + +/** + * Configure snapshot testing. + */ +chai.use(jestSnapshotPlugin()); +addSerializer(jestApiDOMSerializer); +addSerializer(jestStringSerializer); + +/** + * JSDOM setup. + */ +jsdomGlobal(); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.cjs b/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.cjs deleted file mode 100644 index 923ba6f180..0000000000 --- a/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.cjs +++ /dev/null @@ -1,21 +0,0 @@ -require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); - -const Benchmark = require('benchmark'); - -const parseSyntacticAnalysisIndirectBench = require('./parse-syntactic-analysis-indirect.cjs'); -const lexicalAnalysisBench = require('./lexical-analysis.cjs'); - -const suite = new Benchmark.Suite(); - -suite - .add(parseSyntacticAnalysisIndirectBench) - .add(lexicalAnalysisBench) - // add listeners - .on('cycle', function (event) { - console.info(String(event.target)); - }) - .on('complete', function () { - console.info('\nAll benchmarks have completed'); - }) - // run - .run(); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.ts b/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.ts new file mode 100644 index 0000000000..b81fab7d49 --- /dev/null +++ b/packages/apidom-parser-adapter-yaml-1-2/test/perf/index.ts @@ -0,0 +1,20 @@ +import Benchmark from 'benchmark'; +import type { Event } from 'benchmark'; + +import parseSyntacticAnalysisIndirectBench from './parse-syntactic-analysis-indirect'; +import lexicalAnalysisBench from './lexical-analysis'; + +const suite = new Benchmark.Suite(); + +suite + .add(parseSyntacticAnalysisIndirectBench) + .add(lexicalAnalysisBench) + // add listeners + .on('cycle', function (event: Event) { + console.info(String(event.target)); + }) + .on('complete', function () { + console.info('\nAll benchmarks have completed'); + }) + // run + .run(); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.cjs b/packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.ts similarity index 51% rename from packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.cjs rename to packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.ts index e8f7a18c74..c0b4450728 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.cjs +++ b/packages/apidom-parser-adapter-yaml-1-2/test/perf/lexical-analysis.ts @@ -1,11 +1,12 @@ -require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import Benchmark from 'benchmark'; +import type { Event, Deferred } from 'benchmark'; -const fs = require('node:fs'); -const path = require('node:path'); -const Benchmark = require('benchmark'); - -const { default: analyze } = require('../../src/lexical-analysis/node'); +import analyze from '../../src/lexical-analysis/node'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const fixturePath = path.join(__dirname, 'fixtures/data.yaml'); const source = fs.readFileSync(fixturePath).toString(); @@ -14,22 +15,22 @@ const options = { defer: true, minSamples: 600, expected: '662 ops/sec ±2.54% (670 runs sampled)', - async fn(deferred) { + async fn(deferred: Deferred) { await analyze(source); deferred.resolve(); }, }; -module.exports = options; +export default options; // we're running as a script -if (module.parent === null) { +if (import.meta.url === `file://${process.argv[1]}`) { const bench = new Benchmark({ ...options, - onComplete(event) { + onComplete(event: Event) { console.info(String(event.target)); }, - onError(event) { + onError(event: Event) { console.error(event); }, }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.cjs b/packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.ts similarity index 52% rename from packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.cjs rename to packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.ts index 7f7054124f..dd66be11aa 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.cjs +++ b/packages/apidom-parser-adapter-yaml-1-2/test/perf/parse-syntactic-analysis-indirect.ts @@ -1,11 +1,12 @@ -require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import Benchmark from 'benchmark'; +import type { Event, Deferred } from 'benchmark'; -const fs = require('node:fs'); -const path = require('node:path'); -const Benchmark = require('benchmark'); - -const { parse: parseSyntacticAnalysisIndirect } = require('../../src/adapter-node'); +import { parse as parseSyntacticAnalysisIndirect } from '../../src/adapter-node'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const fixturePath = path.join(__dirname, 'fixtures/data.yaml'); const source = fs.readFileSync(fixturePath).toString(); @@ -14,22 +15,22 @@ const options = { defer: true, minSamples: 600, expected: '68.33 ops/sec ±0.29% (675 runs sampled)', - async fn(deferred) { + async fn(deferred: Deferred) { await parseSyntacticAnalysisIndirect(source); deferred.resolve(); }, }; -module.exports = options; +export default options; // we're running as a script -if (module.parent === null) { +if (import.meta.url === `file://${process.argv[1]}`) { const bench = new Benchmark({ ...options, - onComplete(event) { + onComplete(event: Event) { console.info(String(event.target)); }, - onError(event) { + onError(event: Event) { console.error(event); }, }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.ts.snap b/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap similarity index 100% rename from packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.ts.snap rename to packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/wasm-loader.ts b/packages/apidom-parser-adapter-yaml-1-2/test/wasm-loader.ts new file mode 100644 index 0000000000..eee351ede8 --- /dev/null +++ b/packages/apidom-parser-adapter-yaml-1-2/test/wasm-loader.ts @@ -0,0 +1,39 @@ +import { fileURLToPath } from 'node:url'; + +type NextLoad = ( + url: string, + context: { format?: string }, +) => Promise<{ format: string; source: string }>; + +// resolve hook to catch .wasm files +export async function resolve( + specifier: string, + context: { parentURL: string }, + nextResolve: Function, // eslint-disable-line @typescript-eslint/ban-types +) { + if (specifier.endsWith('.wasm')) { + const resolved = new URL(specifier, context.parentURL).href; + return { + url: resolved, + shortCircuit: true, // stop further hooks when we handle .wasm + }; + } + + // delegate to the next loader in the chain + return nextResolve(specifier, context, nextResolve); +} + +// load hook to provide the file path for .wasm files +export async function load(url: string, context: { format?: string }, nextLoad: NextLoad) { + if (url.endsWith('.wasm')) { + const wasmFilePath = fileURLToPath(url); + return { + format: 'module', // define this as an ES module + source: `export default ${JSON.stringify(wasmFilePath)};`, // export file path as a string + shortCircuit: true, // stop further processing for .wasm files + }; + } + + // delegate to the next loader in the chain for all other files + return nextLoad(url, context); +} diff --git a/scripts/jest-serializer-apidom.cjs b/scripts/jest-serializer-apidom.cjs deleted file mode 100644 index baee962ba3..0000000000 --- a/scripts/jest-serializer-apidom.cjs +++ /dev/null @@ -1,6 +0,0 @@ -const { isElement, dehydrate } = require('@swagger-api/apidom-core'); - -module.exports = { - test: isElement, - print: (val) => JSON.stringify(dehydrate(val), null, 2), -}; diff --git a/scripts/jest-serializer-string.cjs b/scripts/jest-serializer-string.cjs deleted file mode 100644 index 969d21efcc..0000000000 --- a/scripts/jest-serializer-string.cjs +++ /dev/null @@ -1,7 +0,0 @@ -const { identity } = require('ramda'); -const { isString } = require('ramda-adjunct'); - -module.exports = { - test: isString, - print: identity, -};