|
| 1 | +import { analyze } from '../../src/analyze'; |
| 2 | +import { Referencer } from '../../src/referencer'; |
| 3 | +import { TSESTree, EcmaVersion, Lib } from '@typescript-eslint/types'; |
| 4 | + |
| 5 | +jest.mock('../../src/referencer'); |
| 6 | +jest.mock('../../src/ScopeManager'); |
| 7 | + |
| 8 | +describe('ecma version mapping', () => { |
| 9 | + it("should map to 'esnext' when unsuported and new", () => { |
| 10 | + expectMapping(2042, 'esnext'); |
| 11 | + expectMapping(42, 'esnext'); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should map to 'es5' when unsuported and old", () => { |
| 15 | + expectMapping(2002, 'es5'); |
| 16 | + expectMapping(2, 'es5'); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should map to 'es{year}' when supported and >= 6", () => { |
| 20 | + expectMapping(2015, 'es2015'); |
| 21 | + expectMapping(6, 'es2015'); |
| 22 | + expectMapping(2020, 'es2020'); |
| 23 | + expectMapping(11, 'es2020'); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should map to 'es5' when 5 or 3", () => { |
| 27 | + expectMapping(5, 'es5'); |
| 28 | + expectMapping(3, 'es5'); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should map to 'es2018' when undefined", () => { |
| 32 | + expectMapping(undefined, 'es2018'); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +const fakeNode = ({} as unknown) as TSESTree.Node; |
| 37 | + |
| 38 | +function expectMapping(ecmaVersion: number | undefined, lib: Lib): void { |
| 39 | + (Referencer as jest.Mock).mockClear(); |
| 40 | + analyze(fakeNode, { ecmaVersion: ecmaVersion as EcmaVersion }); |
| 41 | + expect(Referencer).toHaveBeenCalledWith( |
| 42 | + expect.objectContaining({ lib: [lib] }), |
| 43 | + expect.any(Object), |
| 44 | + ); |
| 45 | +} |
0 commit comments