Skip to content

Commit

Permalink
[Tests] fix tests for older nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 14, 2023
1 parent 261ee3a commit 4c6fa3e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
13 changes: 7 additions & 6 deletions tests/src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import * as path from 'path';
import isCoreModule from 'is-core-module';

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

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

it("should return 'builtin' for node.js modules", function () {
expect(importType('fs', context)).to.equal('builtin');
expect(importType('node:fs', context)).to.equal('builtin');
expect(importType('fs/promises', context)).to.equal('builtin');
expect(importType('node:fs/promises', context)).to.equal('builtin');
expect(importType('path', context)).to.equal('builtin');
expect(importType('node:path', context)).to.equal('builtin');
['fs', 'fs/promises', 'path'].filter((x) => isCoreModule(x)).forEach((x) => {
expect(importType(x, context)).to.equal('builtin');
if (isCoreModule(`node:${x}`)) {
expect(importType(`node:${x}`, context)).to.equal('builtin');
}
});
});

it("should return 'external' for non-builtin modules without a relative path", function () {
Expand Down
113 changes: 58 additions & 55 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import eslintPkg from 'eslint/package.json';
import semver from 'semver';
import flatMap from 'array.prototype.flatmap';
import { resolve } from 'path';
import isCoreModule from 'is-core-module';
import { default as babelPresetFlow } from 'babel-preset-flow';

const ruleTester = new RuleTester();
Expand Down Expand Up @@ -2962,7 +2963,7 @@ context('TypeScript', function () {
],
}),
],
invalid: [
invalid: [].concat(
// Option alphabetize: {order: 'asc'}
test({
code: `
Expand Down Expand Up @@ -3186,53 +3187,22 @@ context('TypeScript', function () {
],
}),

test({
code: `
import express from 'express';
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
output: `
import chpro from 'node:child_process';
import express from 'express';
import log4js from 'log4js';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
}],
errors: [
{ message: '`node:child_process` import should occur before import of `express`' },
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}),

test({
code: `
import express from 'express';
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
output: `
import chpro from 'node:child_process';
import express from 'express';
import log4js from 'log4js';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
[
isCoreModule('node:child_process') && isCoreModule('node:fs/promises') ? [
test({
code: `
import express from 'express';
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
output: `
import chpro from 'node:child_process';
import express from 'express';
import log4js from 'log4js';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
'builtin',
'external',
'internal',
Expand All @@ -3242,14 +3212,47 @@ context('TypeScript', function () {
'object',
'type',
],
}],
errors: [
{ message: '`node:child_process` import should occur before import of `express`' },
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}],
errors: [
{ message: '`node:child_process` import should occur before import of `express`' },
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}),
],
}),

test({
code: `
import express from 'express';
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
output: `
import chpro from 'node:child_process';
import express from 'express';
import log4js from 'log4js';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
[
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
],
}],
errors: [
{ message: '`node:child_process` import should occur before import of `express`' },
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}),
] : [],
),
});
});
});
Expand Down

0 comments on commit 4c6fa3e

Please sign in to comment.