Skip to content

Commit

Permalink
⚒ fix tests on old ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 5, 2019
1 parent b57a4f9 commit 644e999
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 37 deletions.
54 changes: 38 additions & 16 deletions tests/lib/rules/file-extension-in-import.js
Expand Up @@ -5,9 +5,23 @@
"use strict"

const path = require("path")
const RuleTester = require("eslint").RuleTester
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/file-extension-in-import")

const DynamicImportSupported = (() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const messages = new Linter().verify("import(s)", config)
return messages.length === 0
})()

if (!DynamicImportSupported) {
//eslint-disable-next-line no-console
console.warn(
"[%s] Skip tests for 'import()'",
path.basename(__filename, ".js")
)
}

function fixture(filename) {
return path.resolve(
__dirname,
Expand Down Expand Up @@ -240,20 +254,28 @@ new RuleTester({
},

// import()
{
filename: fixture("test.js"),
code: "function f() { import('./a') }",
output: "function f() { import('./a.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "requireExt", data: { ext: ".js" } }],
},
{
filename: fixture("test.js"),
code: "function f() { import('./a.js') }",
output: "function f() { import('./a') }",
options: ["never"],
parserOptions: { ecmaVersion: 2020 },
errors: [{ messageId: "forbidExt", data: { ext: ".js" } }],
},
...(DynamicImportSupported
? [
{
filename: fixture("test.js"),
code: "function f() { import('./a') }",
output: "function f() { import('./a.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: [
{ messageId: "requireExt", data: { ext: ".js" } },
],
},
{
filename: fixture("test.js"),
code: "function f() { import('./a.js') }",
output: "function f() { import('./a') }",
options: ["never"],
parserOptions: { ecmaVersion: 2020 },
errors: [
{ messageId: "forbidExt", data: { ext: ".js" } },
],
},
]
: []),
],
})
32 changes: 25 additions & 7 deletions tests/lib/rules/no-extraneous-import.js
Expand Up @@ -5,9 +5,23 @@
"use strict"

const path = require("path")
const { RuleTester } = require("eslint")
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-extraneous-import")

const DynamicImportSupported = (() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const messages = new Linter().verify("import(s)", config)
return messages.length === 0
})()

if (!DynamicImportSupported) {
//eslint-disable-next-line no-console
console.warn(
"[%s] Skip tests for 'import()'",
path.basename(__filename, ".js")
)
}

/**
* Makes a file path to a fixture.
* @param {string} name - A name.
Expand Down Expand Up @@ -87,11 +101,15 @@ ruleTester.run("no-extraneous-import", rule, {
},

// import()
{
filename: fixture("dependencies/a.js"),
code: "function f() { import('bbb') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"bbb" is extraneous.'],
},
...(DynamicImportSupported
? [
{
filename: fixture("dependencies/a.js"),
code: "function f() { import('bbb') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"bbb" is extraneous.'],
},
]
: []),
],
})
32 changes: 25 additions & 7 deletions tests/lib/rules/no-missing-import.js
Expand Up @@ -5,9 +5,23 @@
"use strict"

const path = require("path")
const { RuleTester } = require("eslint")
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-missing-import")

const DynamicImportSupported = (() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const messages = new Linter().verify("import(s)", config)
return messages.length === 0
})()

if (!DynamicImportSupported) {
//eslint-disable-next-line no-console
console.warn(
"[%s] Skip tests for 'import()'",
path.basename(__filename, ".js")
)
}

/**
* Makes a file path to a fixture.
* @param {string} name - A name.
Expand Down Expand Up @@ -212,11 +226,15 @@ ruleTester.run("no-missing-import", rule, {
},

// import()
{
filename: fixture("test.js"),
code: "function f() { import('no-exist-package-0') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"no-exist-package-0" is not found.'],
},
...(DynamicImportSupported
? [
{
filename: fixture("test.js"),
code: "function f() { import('no-exist-package-0') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"no-exist-package-0" is not found.'],
},
]
: []),
],
})
32 changes: 25 additions & 7 deletions tests/lib/rules/no-unpublished-import.js
Expand Up @@ -5,9 +5,23 @@
"use strict"

const path = require("path")
const { RuleTester } = require("eslint")
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-unpublished-import")

const DynamicImportSupported = (() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const messages = new Linter().verify("import(s)", config)
return messages.length === 0
})()

if (!DynamicImportSupported) {
//eslint-disable-next-line no-console
console.warn(
"[%s] Skip tests for 'import()'",
path.basename(__filename, ".js")
)
}

/**
* Makes a file path to a fixture.
* @param {string} name - A name.
Expand Down Expand Up @@ -246,11 +260,15 @@ ruleTester.run("no-unpublished-import", rule, {
},

// import()
{
filename: fixture("2/test.js"),
code: "function f() { import('./ignore1.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"./ignore1.js" is not published.'],
},
...(DynamicImportSupported
? [
{
filename: fixture("2/test.js"),
code: "function f() { import('./ignore1.js') }",
parserOptions: { ecmaVersion: 2020 },
errors: ['"./ignore1.js" is not published.'],
},
]
: []),
],
})

0 comments on commit 644e999

Please sign in to comment.