Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

test: migrate tests to node test_runner #183

Closed
wants to merge 2 commits into from

Conversation

EnzoDOROSARIO
Copy link

  • Migrate all tests to the bundled Node.js test_runner
  • Remove Mocha, chai and tape from dependencies
  • Add glob to the dev dependencies (I checked what NodeSecure/cli was doing for that)

Resolve #180

package.json Outdated Show resolved Hide resolved
@@ -11,7 +11,8 @@
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "mocha --parallel && npm run test:tsd",
"test-only": "glob -c \"node --loader ts-node/esm --no-warnings --test\" \"test/**/*.spec.ts\"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other project we use tsx (I guess we can replace ts-node)

glob -c \"tsx --test\" \"./test/**/*.spec.ts\"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with using tsx to run tests, is that it make them fail because it fail to do some imports. The problem is due to the fact that we use "type": "module" inside our package.json, removing this fix the tests. The tsx project is aware of the problem, an issue is open here.

Copy link
Member

@PierreDemailly PierreDemailly Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It (can) works with tsx.

npm i -D tsx

package.json:
"test-only": "glob -c \"tsx --test\" \"test/**/*.spec.ts\"",

src/index.ts

export { type RC, type Author, JSONSchema, homedir } from "./rc.js";

instead of

export { RC, Author, JSONSchema, homedir } from "./rc.js";

src/rc.ts

import { generateCIConfiguration, type CiConfiguration, type CiWarnings } from "./projects/ci.js";
import { generateReportConfiguration, type ReportConfiguration, type ReportChart } from "./projects/report.js";
import { generateScannerConfiguration, type ScannerConfiguration, type Author } from "./projects/scanner.js";

instead of

import { generateCIConfiguration, CiConfiguration, CiWarnings } from "./projects/ci.js";
import { generateReportConfiguration, ReportConfiguration, ReportChart } from "./projects/report.js";
import { generateScannerConfiguration, ScannerConfiguration, Author } from "./projects/scanner.js";

Tested with Node v18, v20, v21

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please migrate, we use tsx in all our projects

@fraxken fraxken requested a review from PierreDemailly March 19, 2024 01:15
@EnzoDOROSARIO EnzoDOROSARIO requested a review from fraxken March 21, 2024 18:57
@fraxken fraxken closed this May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate to Node.js test_runner
3 participants