Skip to content

Commit f6982fa

Browse files
committed
test: setup cases
1 parent 54eb51b commit f6982fa

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"type-fest": "0.15.1"
4+
}
5+
}

tests/src/rules/no-extraneous-dependencies.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from '../utils'
1+
import { test, getTSParsers } from '../utils'
22
import * as path from 'path'
33
import * as fs from 'fs'
44

@@ -17,6 +17,7 @@ const packageFileWithSyntaxErrorMessage = (() => {
1717
}
1818
})()
1919
const packageDirWithFlowTyped = path.join(__dirname, '../../files/with-flow-typed')
20+
const packageDirWithTypescriptDevDependencies = path.join(__dirname, '../../files/with-typescript-dev-dependencies')
2021
const packageDirMonoRepoRoot = path.join(__dirname, '../../files/monorepo')
2122
const packageDirMonoRepoWithNested = path.join(__dirname, '../../files/monorepo/packages/nested-package')
2223
const packageDirWithEmpty = path.join(__dirname, '../../files/empty')
@@ -312,3 +313,35 @@ ruleTester.run('no-extraneous-dependencies', rule, {
312313
}),
313314
],
314315
})
316+
317+
describe('TypeScript', function () {
318+
getTSParsers().forEach((parser) => {
319+
const parserConfig = {
320+
parser: parser,
321+
settings: {
322+
'import/parsers': { [parser]: ['.ts'] },
323+
'import/resolver': { 'eslint-import-resolver-typescript': true },
324+
},
325+
}
326+
327+
ruleTester.run('no-extraneous-dependencies', rule, {
328+
valid: [
329+
test(Object.assign({
330+
code: 'import type { PackageJson } from "type-fest";',
331+
filename: path.join(packageDirWithTypescriptDevDependencies, 'file.ts'),
332+
options: [{packageDir: packageDirWithTypescriptDevDependencies, devDependencies: false }],
333+
}, parserConfig)),
334+
],
335+
invalid: [
336+
test(Object.assign({
337+
code: 'import { PackageJson } from "type-fest";',
338+
filename: path.join(packageDirWithTypescriptDevDependencies, 'file.ts'),
339+
options: [{packageDir: packageDirWithTypescriptDevDependencies, devDependencies: false }],
340+
errors: [{
341+
message: "'type-fest' should be listed in the project's dependencies, not devDependencies.",
342+
}],
343+
}, parserConfig)),
344+
],
345+
})
346+
})
347+
})

0 commit comments

Comments
 (0)