From bae7f7441abe575e4c701499d3a6fd1b9fa8c98e Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 21 Nov 2023 07:44:48 +0100 Subject: [PATCH] Running unit tests with TypeScript 5.3 --- .github/workflows/ci.yml | 14 ++++++------ gulpfile.js | 14 +++++------- package.json | 3 ++- test/eslint-plugin-tstest/index.js | 3 ++- test/spec/ts-defs.spec.mjs | 17 ++++++++++++++ test/spec/ts-defs/110.tstest | 36 +++++++++++++++++++++--------- 6 files changed, 58 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5115e96..0922f36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,10 +11,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: '20' + node-version: ^20.8 - run: | npm install gulp make-ts-defs @@ -35,11 +35,11 @@ jobs: strategy: matrix: - node-version: ['16.0.0', '16', '18', '20'] + node-version: ['16.0.0', '16', '18', '20', '21'] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install @@ -67,7 +67,7 @@ jobs: deno-version: [v1.24, v1.x] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: denoland/setup-deno@v1 with: deno-version: ${{ matrix.deno-version }} diff --git a/gulpfile.js b/gulpfile.js index d94cf8e..7c67ec5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -101,7 +101,7 @@ task const JS_EXAMPLE_RULES = { - 'comma-dangle': + '@stylistic/comma-dangle': [ 'error', { @@ -123,14 +123,10 @@ task varsIgnorePattern: '^(?:Green|WhiteUnit)Circle$', }, ], - 'quotes': ['error', 'double'], + '@stylistic/quotes': ['error', 'double'], }; - const TS_EXAMPLE_RULES = - Object.fromEntries - ( - Object.entries(JS_EXAMPLE_RULES) - .map(([key, value]) => [`@typescript-eslint/${key}`, value]), - ); + const { 'no-unused-vars': noUnusedVars, ...TS_EXAMPLE_RULES } = JS_EXAMPLE_RULES; + TS_EXAMPLE_RULES['@typescript-eslint/no-unused-vars'] = noUnusedVars; const overrideConfig = createConfig ( @@ -160,7 +156,7 @@ task }, { files: 'lib/**/*.d.ts', - rules: { 'max-len': 'off' }, + rules: { '@stylistic/max-len': 'off' }, }, { files: '*.tstest', diff --git a/package.json b/package.json index d1908f2..158e9e9 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,8 @@ "typescript_4.9": "npm:typescript@4.9", "typescript_5.0": "npm:typescript@5.0", "typescript_5.1": "npm:typescript@5.1", - "typescript_5.2": "npm:typescript@5.2" + "typescript_5.2": "npm:typescript@5.2", + "typescript_5.3": "npm:typescript@5.3" }, "engines": { "node": ">=16.0.0" diff --git a/test/eslint-plugin-tstest/index.js b/test/eslint-plugin-tstest/index.js index 8fc677d..233b8e8 100644 --- a/test/eslint-plugin-tstest/index.js +++ b/test/eslint-plugin-tstest/index.js @@ -62,7 +62,8 @@ function preprocess(text, filename) fileNameToTestCaseMap.set(filename, testCase); const polytypeMode = testCase.polytypeMode ?? 'global'; const importStatement = getImportStatement(polytypeMode); - const testDataText = `void\n${testCase.testData}\n; // eslint-disable-line semi-style\n`; + const testDataText = + `void\n${testCase.testData}\n; // eslint-disable-line @stylistic/semi-style\n`; const processedCode = processTestCase(testCase, importStatement); const returnValue = [{ text: processedCode, filename: '/..' }, { text: testDataText, filename: '/test-data.mjs' }]; diff --git a/test/spec/ts-defs.spec.mjs b/test/spec/ts-defs.spec.mjs index bb897b0..5a6ac94 100644 --- a/test/spec/ts-defs.spec.mjs +++ b/test/spec/ts-defs.spec.mjs @@ -128,6 +128,22 @@ function defineTests(typescriptPkgName) `${actualMessagesString}`, ); } + else if (Array.isArray(expectedMessage)) + { + assert.equal + ( + actualErrorCount, + 1, + `expected exactly 1 compiler error, but got ${actualErrorCount}:` + + `${actualMessagesString}`, + ); + const [actualMessage] = testCase.actualMessages; + assert + ( + expectedMessage.includes(actualMessage), + `Actual message:\n${actualMessage}`, + ); + } else { assert.equal @@ -187,5 +203,6 @@ describe describe('TypeScript 5.0', () => defineTests('typescript_5.0')); describe('TypeScript 5.1', () => defineTests('typescript_5.1')); describe('TypeScript 5.2', () => defineTests('typescript_5.2')); + describe('TypeScript 5.3', () => defineTests('typescript_5.3')); }, ); diff --git a/test/spec/ts-defs/110.tstest b/test/spec/ts-defs/110.tstest index 4cdc8be..6b44286 100644 --- a/test/spec/ts-defs/110.tstest +++ b/test/spec/ts-defs/110.tstest @@ -2,17 +2,31 @@ { title: 'Superconstructor argument referencing indirect superclass', expectedMessage: - 'No overload matches this call.\n' + - ' Overload 1 of 2, \'(args_0?: readonly [] | undefined): ClusteredPrototype<[typeof B]>\', ' + - 'gave the following error.\n' + - ' Argument of type \'{ super: typeof A; }\' is not assignable to parameter of type ' + - '\'readonly []\'.\n' + - ' Object literal may only specify known properties, and \'super\' does not exist in ' + - 'type \'readonly []\'.\n' + - ' Overload 2 of 2, \'(...args: Readonly>[]): ' + - 'ClusteredPrototype<[typeof B]>\', gave the following error.\n' + - ' Type \'typeof A\' is not assignable to type \'typeof B\'.\n' + - ' Property \'b\' is missing in type \'A\' but required in type \'B\'.', + [ + // TypeScript < 5.3 + 'No overload matches this call.\n' + + ' Overload 1 of 2, \'(args_0?: readonly [] | undefined): ClusteredPrototype<[typeof ' + + 'B]>\', gave the following error.\n' + + ' Argument of type \'{ super: typeof A; }\' is not assignable to parameter of type ' + + '\'readonly []\'.\n' + + ' Object literal may only specify known properties, and \'super\' does not exist in ' + + 'type \'readonly []\'.\n' + + ' Overload 2 of 2, \'(...args: Readonly>[]): ' + + 'ClusteredPrototype<[typeof B]>\', gave the following error.\n' + + ' Type \'typeof A\' is not assignable to type \'typeof B\'.\n' + + ' Property \'b\' is missing in type \'A\' but required in type \'B\'.', + + // TypeScript >= 5.3 + 'No overload matches this call.\n' + + ' Overload 1 of 2, \'(args_0?: readonly [] | undefined): ClusteredPrototype<[typeof ' + + 'B]>\', gave the following error.\n' + + ' Object literal may only specify known properties, and \'super\' does not exist in ' + + 'type \'readonly []\'.\n' + + ' Overload 2 of 2, \'(...args: Readonly>[]): ' + + 'ClusteredPrototype<[typeof B]>\', gave the following error.\n' + + ' Type \'typeof A\' is not assignable to type \'typeof B\'.\n' + + ' Property \'b\' is missing in type \'A\' but required in type \'B\'.', + ], } */