Skip to content

Commit

Permalink
chore(dev-infra): enable eslint rule `@typescript-eslint/prefer-ts-ex…
Browse files Browse the repository at this point in the history
…pect-error` (#1677)
  • Loading branch information
ahnpnl authored May 24, 2020
1 parent be32e7b commit 9c6f98e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ module.exports = {
default: 'array',
},
],
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-types': [
'error',
{
Expand Down Expand Up @@ -229,6 +228,7 @@ module.exports = {
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/prefer-readonly': 'error',
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/triple-slash-reference': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import hello from './enable-automock'

test('original implementation', () => {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(hello._isMockFunction).toBeTruthy()
})
20 changes: 10 additions & 10 deletions e2e/__tests__/__snapshots__/hoisting.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ exports[`Hoisting jest.enableAutomock() should pass using template "default": io
var enable_automock_1 = require("./enable-automock");
test('original implementation', function () {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(enable_automock_1.default._isMockFunction).toBeTruthy();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoiPGN3ZD4vZW5hYmxlLWF1dG9tb2NrLnNwZWMudHMiLCJtYXBwaW5ncyI6Ijs7QUFBQSxJQUFJLENBQUMsY0FBYyxFQUFFLENBQUE7QUFFckIscURBQXFDO0FBRXJDLElBQUksQ0FBQyx5QkFBeUIsRUFBRTtJQUM5Qix5Q0FBeUM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oJ29yaWdpbmFsIGltcGxlbWVudGF0aW9uJywgKCkgPT4ge1xuICAvLyBub3cgd2UgaGF2ZSB0aGUgbW9ja2VkIGltcGxlbWVudGF0aW9uLFxuICAvLyBAdHMtZXhwZWN0LWVycm9yXG4gIGV4cGVjdChoZWxsby5faXNNb2NrRnVuY3Rpb24pLnRvQmVUcnV0aHkoKVxufSlcbiJdLCJ2ZXJzaW9uIjozfQ==
===[ INLINE SOURCE MAPS ]=======================================================
file: <cwd>/enable-automock.spec.ts
mappings: >-
;;AAAA,IAAI,CAAC,cAAc,EAAE,CAAA;AAErB,qDAAqC;AAErC,IAAI,CAAC,yBAAyB,EAAE;IAC9B,yCAAyC;IACzC,aAAa;IACb,MAAM,CAAC,yBAAK,CAAC,eAAe,CAAC,CAAC,UAAU,EAAE,CAAA;AAC5C,CAAC,CAAC,CAAA
;;AAAA,IAAI,CAAC,cAAc,EAAE,CAAA;AAErB,qDAAqC;AAErC,IAAI,CAAC,yBAAyB,EAAE;IAC9B,yCAAyC;IACzC,mBAAmB;IACnB,MAAM,CAAC,yBAAK,CAAC,eAAe,CAAC,CAAC,UAAU,EAAE,CAAA;AAC5C,CAAC,CAAC,CAAA
names: []
sources:
- <cwd>/enable-automock.spec.ts
Expand All @@ -210,7 +210,7 @@ exports[`Hoisting jest.enableAutomock() should pass using template "default": io
test('original implementation', () => {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(hello._isMockFunction).toBeTruthy()
})
version: 3
Expand Down Expand Up @@ -258,10 +258,10 @@ exports[`Hoisting jest.enableAutomock() should pass using template "with-babel-7
test('original implementation', function () {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(enable_automock_1.default._isMockFunction).toBeTruthy();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJtYXBwaW5ncyI6Ijs7QUFBQSxjQUFLLGNBQUw7Ozs7Ozs7Ozs7Ozs7Ozs7QUFFQSxJQUFBLGlCQUFBLEdBQUEsT0FBQSxDQ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20gJy4vZW5hYmxlLWF1dG9tb2NrJ1xuXG50ZXN0KCdvcmlnaW5hbCBpbXBsZW1lbnRhdGlvbicsICgpID0+IHtcbiAgLy8gbm93IHdlIGhhdmUgdGhlIG1vY2tlZCBpbXBsZW1lbnRhdGlvbixcbiAgLy8gQHRzLWV4cGVjdC1lcnJvclxuICBleHBlY3QoaGVsbG8uX2lzTW9ja0Z1bmN0aW9uKS50b0JlVHJ1dGh5KClcbn0pXG4iXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
mappings: >-
;;AAAA,cAAK,cAAL;;;;;;;;;;;;;;;;AAEA,IAAA,iBAAA,GAAA,OAAA,CAAA,mBAAA,CAAA;;AAEA,IAAI,CAAC,yBAAD,EAA4B,YAAA;AAC9B;AACA;AACA,EAAA,MAAM,CAAC,iBAAA,CAAA,OAAA,CAAM,eAAP,CAAN,CAA8B,UAA9B;AACD,CAJG,CAAJ
Expand All @@ -276,7 +276,7 @@ exports[`Hoisting jest.enableAutomock() should pass using template "with-babel-7
test('original implementation', () => {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(hello._isMockFunction).toBeTruthy()
})
version: 3
Expand Down Expand Up @@ -324,10 +324,10 @@ exports[`Hoisting jest.enableAutomock() should pass using template "with-babel-7
test('original implementation', function () {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(enable_automock_1.default._isMockFunction).toBeTruthy();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJtYXBwaW5ncyI6Ijs7QUFBQSxjQUFLLGNBQUw7Ozs7Ozs7Ozs7Ozs7Ozs7QUFFQSxJQUFBLGlCQUFBLEdBQUEsT0FBQSxDQUFBLG1CQUFBLENBQUE7O0FBRUEsSUFBSSxDQUFDLHlCQUFELEVBQTRCLFlBQUE7QUFDOUI7QUFDQTtBQUNBLEVBQUEsTUFBTSxDQUFDLGlCQUFBLENBQUEsT0FBQSxDQUFNLGVBQVAsQ0FBTixDQUE4QixVQUE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LWV4cGVjdC1lcnJvclxuICBleHBlY3QoaGVsbG8uX2lzTW9ja0Z1bmN0aW9uKS50b0JlVHJ1dGh5KClcbn0pXG4iXSwidmVyc2lvbiI6M30=
===[ INLINE SOURCE MAPS ]=======================================================
mappings: >-
;;AAAA,cAAK,cAAL;;;;;;;;;;;;;;;;AAEA,IAAA,iBAAA,GAAA,OAAA,CAAA,mBAAA,CAAA;;AAEA,IAAI,CAAC,yBAAD,EAA4B,YAAA;AAC9B;AACA;AACA,EAAA,MAAM,CAAC,iBAAA,CAAA,OAAA,CAAM,eAAP,CAAN,CAA8B,UAA9B;AACD,CAJG,CAAJ
Expand All @@ -342,7 +342,7 @@ exports[`Hoisting jest.enableAutomock() should pass using template "with-babel-7
test('original implementation', () => {
// now we have the mocked implementation,
// @ts-ignore
// @ts-expect-error
expect(hello._isMockFunction).toBeTruthy()
})
version: 3
Expand Down
68 changes: 35 additions & 33 deletions e2e/__tests__/hoisting.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import { allValidPackageSets } from '../__helpers__/templates'
import { configureTestCase } from '../__helpers__/test-case'

describe('Hoisting jest.mock() & jest.unmock()', () => {
const testCase = configureTestCase('hoisting/mock-unmock', {
writeIo: true,
})
describe('Hoisting', () => {
describe('jest.mock() & jest.unmock()', () => {
const testCase = configureTestCase('hoisting/mock-unmock', {
writeIo: true,
})

testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-mockUnmock')
expect(result.ioFor('mock-unmock.spec.ts')).toMatchSnapshot('io-mockUnmock')
testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-mockUnmock')
expect(result.ioFor('mock-unmock.spec.ts')).toMatchSnapshot('io-mockUnmock')
})
})
})
})

describe('Hoisting jest.enableAutomock()', () => {
const testCase = configureTestCase('hoisting/enable-automock', { writeIo: true })
describe('jest.enableAutomock()', () => {
const testCase = configureTestCase('hoisting/enable-automock', { writeIo: true })

testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-enableAutomock')
expect(result.ioFor('enable-automock.spec.ts')).toMatchSnapshot('io-enableAutomock')
testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-enableAutomock')
expect(result.ioFor('enable-automock.spec.ts')).toMatchSnapshot('io-enableAutomock')
})
})
})
})

describe('Hoisting jest.disableAutomock()', () => {
const testCase = configureTestCase('hoisting/disable-automock', {
writeIo: true,
jestConfig: {
automock: true,
}
})
describe('jest.disableAutomock()', () => {
const testCase = configureTestCase('hoisting/disable-automock', {
writeIo: true,
jestConfig: {
automock: true,
}
})

testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-disableAutomock')
expect(result.ioFor('disable-automock.spec.ts')).toMatchSnapshot('io-disableAutomock')
testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => {
it(testLabel, () => {
const result = runTest()
expect(result.status).toBe(0)
expect(result).toMatchSnapshot('output-disableAutomock')
expect(result.ioFor('disable-automock.spec.ts')).toMatchSnapshot('io-disableAutomock')
})
})
})
})
2 changes: 1 addition & 1 deletion src/compiler/compiler-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function cacheResolvedModules(
logger: Logger,
): void {
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
// @ts-ignore
// @ts-expect-error
const importReferences = program.getSourceFile(fileName)!.imports
/**
* Ugly trick while waiting for https://github.com/microsoft/TypeScript/issues/33994
Expand Down

0 comments on commit 9c6f98e

Please sign in to comment.