Skip to content

Commit

Permalink
Fix: node:test not grouped with <BUILTIN_MODULES> (#143)
Browse files Browse the repository at this point in the history
Following discussion in #142 , this adds an explicit check for
`"node:test"` to `BUILTIN_MODULES_REGEX_STR` in order to properly group
it with other builtin modules.

Test covers:
- `"node:test"` correctly gets grouped in with other builtin node
modules
- `"node:test"` is correctly sorted among other builtin node modules
- `"*node:test"` is NOT grouped in with builtin modules
- `"node:test*"` is NOT grouped in with builtin modules
- `"node"` is NOT grouped in with builtin modules
- `"test"` is NOT grouped in with builtin modules

Fixes #142
  • Loading branch information
IsaiahByDayah authored Jan 31, 2024
1 parent 539e23d commit 8541bb8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export const mergeableImportFlavors = [
importFlavorType,
] as const;

export const BUILTIN_MODULES_REGEX_STR = `^(?:node:)?(?:${builtinModules.join(
// NOTE: 'test' is not included in `builtinModules` so explicitly check for "node:test"
// REF: https://github.com/nodejs/node/issues/42785
export const BUILTIN_MODULES_REGEX_STR = `(^(?:node:)?(?:${builtinModules.join(
'|',
)})$`;
)})$)|(^node:test$)`;

export const BUILTIN_MODULES_SPECIAL_WORD = '<BUILTIN_MODULES>';
/**
Expand Down
25 changes: 25 additions & 0 deletions tests/BuiltinModulesNodeTest/__snapshots__/ppsi.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`groups-node-test-with-builtin-modules.js - typescript-verify > groups-node-test-with-builtin-modules.js 1`] = `
import nodeUtil from 'node:util';
import nodeNodeTestTest from 'node:node:test:test';
import nodeNodeTest from 'node:node:test';
import nodeTestTest from 'node:test:test';
import nodeTest from 'node:test';
import test from 'test'
import node from 'node';
import fs from 'fs';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import fs from "fs";
import nodeTest from "node:test";
import nodeUtil from "node:util";
import node from "node";
import nodeNodeTest from "node:node:test";
import nodeNodeTestTest from "node:node:test:test";
import nodeTestTest from "node:test:test";
import test from "test";
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import nodeUtil from 'node:util';

import nodeNodeTestTest from 'node:node:test:test';
import nodeNodeTest from 'node:node:test';
import nodeTestTest from 'node:test:test';
import nodeTest from 'node:test';
import test from 'test'
import node from 'node';

import fs from 'fs';
12 changes: 12 additions & 0 deletions tests/BuiltinModulesNodeTest/ppsi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {run_spec} from '../../test-setup/run_spec';

run_spec(__dirname, ["typescript"], {
importOrder: [
"",
"<BUILTIN_MODULES>",
"",
"<THIRD_PARTY_MODULES>",
"",
"^[.]",
],
});

0 comments on commit 8541bb8

Please sign in to comment.