Skip to content

Commit

Permalink
Run prefer-export-from test with ESpree (#1978)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 18, 2022
1 parent 615416d commit effcad6
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 61 deletions.
79 changes: 18 additions & 61 deletions test/prefer-export-from.mjs
Expand Up @@ -456,6 +456,24 @@ test.snapshot({
import {type foo as bar} from 'foo';
export {type bar as foo};
`,
outdent`
import json from './foo.json' assert { type: 'json' };
export default json;
`,
outdent`
import * as json from './foo.json' assert { type: 'json' };
export {json};
`,
outdent`
import {foo} from './foo.json' assert { type: 'unknown' };
export {foo};
export {bar} from './foo.json';
`,
outdent`
import {foo} from './foo.json';
export {foo};
export {bar} from './foo.json' assert { type: 'unknown' };
`,
],
});

Expand Down Expand Up @@ -564,64 +582,3 @@ test.snapshot({
].map(code => ({code, options: [{ignoreUsedVariables: true}]})),
});

// TODO: Run test with default parser when it support "import assertions"
test.babel({
testerOptions: {
parserOptions: {
babelOptions: {
parserOpts: {
plugins: ['importAssertions'],
},
},
},
},
valid: [],
invalid: [
{
code: outdent`
import json from './foo.json' assert { type: 'json' };
export default json;
`,
errors: 1,
output: outdent`
\n
export {default} from './foo.json' assert { type: 'json' };
`,
},
{
code: outdent`
import * as json from './foo.json' assert { type: 'json' };
export {json};
`,
errors: 1,
output: outdent`
\n
export * as json from './foo.json' assert { type: 'json' };
`,
},
{
code: outdent`
import {foo} from './foo.json' assert { type: 'unknown' };
export {foo};
export {bar} from './foo.json';
`,
errors: 1,
output: outdent`
\n
export {bar, foo} from './foo.json';
`,
},
{
code: outdent`
import {foo} from './foo.json';
export {foo};
export {bar} from './foo.json' assert { type: 'unknown' };
`,
errors: 1,
output: outdent`
\n
export {bar, foo} from './foo.json' assert { type: 'unknown' };
`,
},
],
});
84 changes: 84 additions & 0 deletions test/snapshots/prefer-export-from.mjs.md
Expand Up @@ -1748,6 +1748,90 @@ Generated by [AVA](https://avajs.dev).
| ^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`foo\`.␊
`

## Invalid #22
1 | import json from './foo.json' assert { type: 'json' };
2 | export default json;

> Output
`␊
1 |␊
2 |␊
3 | export {default} from './foo.json' assert { type: 'json' };␊
`

> Error 1/1
`␊
1 | import json from './foo.json' assert { type: 'json' };␊
> 2 | export default json;␊
| ^^^^^^^^^^^^^^^^^^^^ Use \`export…from\` to re-export \`default\`.␊
`

## Invalid #23
1 | import * as json from './foo.json' assert { type: 'json' };
2 | export {json};

> Output
`␊
1 |␊
2 |␊
3 | export * as json from './foo.json' assert { type: 'json' };␊
`

> Error 1/1
`␊
1 | import * as json from './foo.json' assert { type: 'json' };␊
> 2 | export {json};␊
| ^^^^ Use \`export…from\` to re-export \`json\`.␊
`

## Invalid #24
1 | import {foo} from './foo.json' assert { type: 'unknown' };
2 | export {foo};
3 | export {bar} from './foo.json';

> Output
`␊
1 |␊
2 |␊
3 | export {bar, foo} from './foo.json';␊
`

> Error 1/1
`␊
1 | import {foo} from './foo.json' assert { type: 'unknown' };␊
> 2 | export {foo};␊
| ^^^ Use \`export…from\` to re-export \`foo\`.␊
3 | export {bar} from './foo.json';␊
`

## Invalid #25
1 | import {foo} from './foo.json';
2 | export {foo};
3 | export {bar} from './foo.json' assert { type: 'unknown' };

> Output
`␊
1 |␊
2 |␊
3 | export {bar, foo} from './foo.json' assert { type: 'unknown' };␊
`

> Error 1/1
`␊
1 | import {foo} from './foo.json';␊
> 2 | export {foo};␊
| ^^^ Use \`export…from\` to re-export \`foo\`.␊
3 | export {bar} from './foo.json' assert { type: 'unknown' };␊
`

## Invalid #1
1 | import defaultExport from 'foo';
2 | export {defaultExport as default};
Expand Down
Binary file modified test/snapshots/prefer-export-from.mjs.snap
Binary file not shown.

0 comments on commit effcad6

Please sign in to comment.