Skip to content

Commit a8781f7

Browse files
ProdigySimljharb
authored andcommitted
[Tests] named: Add direct test for export = assignment in TS
Closes #1984.
1 parent 116af31 commit a8781f7

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const someObj = {
2+
FooBar: 12,
3+
};
4+
5+
export = someObj;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true
4+
}
5+
}

tests/src/rules/named.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { test, SYNTAX_CASES, getTSParsers, testFilePath, testVersion, parsers } from '../utils';
22
import { RuleTester } from 'eslint';
3+
import path from 'path';
34

45
import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve';
56

@@ -388,7 +389,16 @@ context('TypeScript', function () {
388389
'import/resolver': { 'eslint-import-resolver-typescript': true },
389390
};
390391

391-
let valid = [];
392+
let valid = [
393+
test({
394+
code: `import x from './typescript-export-assign-object'`,
395+
parser,
396+
parserOptions: {
397+
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-export-assign-object/'),
398+
},
399+
settings,
400+
}),
401+
];
392402
const invalid = [
393403
// TODO: uncomment this test
394404
// test({
@@ -400,6 +410,31 @@ context('TypeScript', function () {
400410
// { message: 'a not found in ./export-star-3/b' },
401411
// ],
402412
// }),
413+
test({
414+
code: `import { NotExported } from './typescript-export-assign-object'`,
415+
parser,
416+
parserOptions: {
417+
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-export-assign-object/'),
418+
},
419+
settings,
420+
errors: [{
421+
message: `NotExported not found in './typescript-export-assign-object'`,
422+
type: 'Identifier',
423+
}],
424+
}),
425+
test({
426+
// `export =` syntax creates a default export only
427+
code: `import { FooBar } from './typescript-export-assign-object'`,
428+
parser,
429+
parserOptions: {
430+
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-export-assign-object/'),
431+
},
432+
settings,
433+
errors: [{
434+
message: `FooBar not found in './typescript-export-assign-object'`,
435+
type: 'Identifier',
436+
}],
437+
}),
403438
];
404439

405440
[

0 commit comments

Comments
 (0)