Skip to content

Commit 4c6fa3e

Browse files
committed
[Tests] fix tests for older nodes
1 parent 261ee3a commit 4c6fa3e

File tree

2 files changed

+65
-61
lines changed

2 files changed

+65
-61
lines changed

tests/src/core/importType.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from 'chai';
22
import * as path from 'path';
3+
import isCoreModule from 'is-core-module';
34

45
import importType, { isExternalModule, isScoped, isAbsolute } from 'core/importType';
56

@@ -16,12 +17,12 @@ describe('importType(name)', function () {
1617
});
1718

1819
it("should return 'builtin' for node.js modules", function () {
19-
expect(importType('fs', context)).to.equal('builtin');
20-
expect(importType('node:fs', context)).to.equal('builtin');
21-
expect(importType('fs/promises', context)).to.equal('builtin');
22-
expect(importType('node:fs/promises', context)).to.equal('builtin');
23-
expect(importType('path', context)).to.equal('builtin');
24-
expect(importType('node:path', context)).to.equal('builtin');
20+
['fs', 'fs/promises', 'path'].filter((x) => isCoreModule(x)).forEach((x) => {
21+
expect(importType(x, context)).to.equal('builtin');
22+
if (isCoreModule(`node:${x}`)) {
23+
expect(importType(`node:${x}`, context)).to.equal('builtin');
24+
}
25+
});
2526
});
2627

2728
it("should return 'external' for non-builtin modules without a relative path", function () {

tests/src/rules/order.js

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import eslintPkg from 'eslint/package.json';
55
import semver from 'semver';
66
import flatMap from 'array.prototype.flatmap';
77
import { resolve } from 'path';
8+
import isCoreModule from 'is-core-module';
89
import { default as babelPresetFlow } from 'babel-preset-flow';
910

1011
const ruleTester = new RuleTester();
@@ -2962,7 +2963,7 @@ context('TypeScript', function () {
29622963
],
29632964
}),
29642965
],
2965-
invalid: [
2966+
invalid: [].concat(
29662967
// Option alphabetize: {order: 'asc'}
29672968
test({
29682969
code: `
@@ -3186,53 +3187,22 @@ context('TypeScript', function () {
31863187
],
31873188
}),
31883189

3189-
test({
3190-
code: `
3191-
import express from 'express';
3192-
import log4js from 'log4js';
3193-
import chpro from 'node:child_process';
3194-
// import fsp from 'node:fs/promises';
3195-
`,
3196-
output: `
3197-
import chpro from 'node:child_process';
3198-
import express from 'express';
3199-
import log4js from 'log4js';
3200-
// import fsp from 'node:fs/promises';
3201-
`,
3202-
options: [{
3203-
groups: [
3204-
'builtin',
3205-
'external',
3206-
'internal',
3207-
'parent',
3208-
'sibling',
3209-
'index',
3210-
'object',
3211-
'type',
3212-
],
3213-
}],
3214-
errors: [
3215-
{ message: '`node:child_process` import should occur before import of `express`' },
3216-
// { message: '`node:fs/promises` import should occur before import of `express`' },
3217-
],
3218-
}),
3219-
3220-
test({
3221-
code: `
3222-
import express from 'express';
3223-
import log4js from 'log4js';
3224-
import chpro from 'node:child_process';
3225-
// import fsp from 'node:fs/promises';
3226-
`,
3227-
output: `
3228-
import chpro from 'node:child_process';
3229-
import express from 'express';
3230-
import log4js from 'log4js';
3231-
// import fsp from 'node:fs/promises';
3232-
`,
3233-
options: [{
3234-
groups: [
3235-
[
3190+
isCoreModule('node:child_process') && isCoreModule('node:fs/promises') ? [
3191+
test({
3192+
code: `
3193+
import express from 'express';
3194+
import log4js from 'log4js';
3195+
import chpro from 'node:child_process';
3196+
// import fsp from 'node:fs/promises';
3197+
`,
3198+
output: `
3199+
import chpro from 'node:child_process';
3200+
import express from 'express';
3201+
import log4js from 'log4js';
3202+
// import fsp from 'node:fs/promises';
3203+
`,
3204+
options: [{
3205+
groups: [
32363206
'builtin',
32373207
'external',
32383208
'internal',
@@ -3242,14 +3212,47 @@ context('TypeScript', function () {
32423212
'object',
32433213
'type',
32443214
],
3215+
}],
3216+
errors: [
3217+
{ message: '`node:child_process` import should occur before import of `express`' },
3218+
// { message: '`node:fs/promises` import should occur before import of `express`' },
32453219
],
3246-
}],
3247-
errors: [
3248-
{ message: '`node:child_process` import should occur before import of `express`' },
3249-
// { message: '`node:fs/promises` import should occur before import of `express`' },
3250-
],
3251-
}),
3252-
],
3220+
}),
3221+
3222+
test({
3223+
code: `
3224+
import express from 'express';
3225+
import log4js from 'log4js';
3226+
import chpro from 'node:child_process';
3227+
// import fsp from 'node:fs/promises';
3228+
`,
3229+
output: `
3230+
import chpro from 'node:child_process';
3231+
import express from 'express';
3232+
import log4js from 'log4js';
3233+
// import fsp from 'node:fs/promises';
3234+
`,
3235+
options: [{
3236+
groups: [
3237+
[
3238+
'builtin',
3239+
'external',
3240+
'internal',
3241+
'parent',
3242+
'sibling',
3243+
'index',
3244+
'object',
3245+
'type',
3246+
],
3247+
],
3248+
}],
3249+
errors: [
3250+
{ message: '`node:child_process` import should occur before import of `express`' },
3251+
// { message: '`node:fs/promises` import should occur before import of `express`' },
3252+
],
3253+
}),
3254+
] : [],
3255+
),
32533256
});
32543257
});
32553258
});

0 commit comments

Comments
 (0)