From 800ea11597a309e07eb90c819366d87dbbd31760 Mon Sep 17 00:00:00 2001 From: johanndev <10048453+johanndev@users.noreply.github.com> Date: Sun, 7 Jan 2024 10:11:06 +0100 Subject: [PATCH 1/3] test: Add PoC for typescript version integration test --- library/tests/integration.test.ts | 31 +++++++++++++++++++++++++++++++ library/tests/testscript.ts | 1 + 2 files changed, 32 insertions(+) create mode 100644 library/tests/integration.test.ts create mode 100644 library/tests/testscript.ts diff --git a/library/tests/integration.test.ts b/library/tests/integration.test.ts new file mode 100644 index 000000000..26b6bc71c --- /dev/null +++ b/library/tests/integration.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, test } from 'vitest'; +import { spawnSync } from 'node:child_process'; +import { join } from 'node:path'; +describe('Integration', () => { + test.each([ + ['4.9.5', false], + ['5.0.2', true], + ])( + 'with TypeScript version %s should work: %s', + async (tsVersion, expectSuccess) => { + const npx = spawnSync('npx', [ + '--yes', + '--package', + `typescript@${tsVersion}`, + 'tsc', + '--noEmit', + '--target', + 'ES6', + join(__dirname, 'testscript.ts'), + ]); + + const npxOutput = npx.output.toString(); + const containsError = npxOutput.includes('error TS'); + if (expectSuccess) { + expect(containsError).toBeFalsy(); + } else { + expect(containsError).toBeTruthy(); + } + } + ); +}); diff --git a/library/tests/testscript.ts b/library/tests/testscript.ts new file mode 100644 index 000000000..03c4def95 --- /dev/null +++ b/library/tests/testscript.ts @@ -0,0 +1 @@ +import * as v from '../dist/index.js'; \ No newline at end of file From c3da5c16e815e7e588b886b06330876bc389b593 Mon Sep 17 00:00:00 2001 From: johanndev <10048453+johanndev@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:18:51 +0100 Subject: [PATCH 2/3] Switch from npx to pnpm dlx --- library/tests/integration.test.ts | 51 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/library/tests/integration.test.ts b/library/tests/integration.test.ts index 26b6bc71c..0a4721ea8 100644 --- a/library/tests/integration.test.ts +++ b/library/tests/integration.test.ts @@ -2,30 +2,31 @@ import { describe, expect, test } from 'vitest'; import { spawnSync } from 'node:child_process'; import { join } from 'node:path'; describe('Integration', () => { - test.each([ - ['4.9.5', false], - ['5.0.2', true], - ])( - 'with TypeScript version %s should work: %s', - async (tsVersion, expectSuccess) => { - const npx = spawnSync('npx', [ - '--yes', - '--package', - `typescript@${tsVersion}`, - 'tsc', - '--noEmit', - '--target', - 'ES6', - join(__dirname, 'testscript.ts'), - ]); + test.each([ + ['4.9.5', false], + ['5.0.2', true], + ])( + 'with TypeScript version %s should work: %s', + (tsVersion, expectSuccess) => { + const npx = spawnSync('pnpm', [ + '--package', + `typescript@${tsVersion}`, + '--silent', + 'dlx', + 'tsc', + '--noEmit', + '--target', + 'ES6', + join(__dirname, 'testscript.ts'), + ]); - const npxOutput = npx.output.toString(); - const containsError = npxOutput.includes('error TS'); - if (expectSuccess) { - expect(containsError).toBeFalsy(); - } else { - expect(containsError).toBeTruthy(); - } - } - ); + const npxOutput = npx.output.toString(); + const containsError = npxOutput.includes('error TS'); + if (expectSuccess) { + expect(containsError).toBeFalsy(); + } else { + expect(containsError).toBeTruthy(); + } + } + ); }); From 94a63cfab66bbacdac34a59d8101f509e0db93c4 Mon Sep 17 00:00:00 2001 From: johanndev <10048453+johanndev@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:22:41 +0100 Subject: [PATCH 3/3] Fix indentations --- library/tests/integration.test.ts | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/library/tests/integration.test.ts b/library/tests/integration.test.ts index 0a4721ea8..5ee930e09 100644 --- a/library/tests/integration.test.ts +++ b/library/tests/integration.test.ts @@ -2,31 +2,31 @@ import { describe, expect, test } from 'vitest'; import { spawnSync } from 'node:child_process'; import { join } from 'node:path'; describe('Integration', () => { - test.each([ - ['4.9.5', false], - ['5.0.2', true], - ])( - 'with TypeScript version %s should work: %s', - (tsVersion, expectSuccess) => { - const npx = spawnSync('pnpm', [ - '--package', - `typescript@${tsVersion}`, - '--silent', - 'dlx', - 'tsc', - '--noEmit', - '--target', - 'ES6', - join(__dirname, 'testscript.ts'), - ]); + test.each([ + ['4.9.5', false], + ['5.0.2', true], + ])( + 'with TypeScript version %s should work: %s', + (tsVersion, expectSuccess) => { + const npx = spawnSync('pnpm', [ + '--package', + `typescript@${tsVersion}`, + '--silent', + 'dlx', + 'tsc', + '--noEmit', + '--target', + 'ES6', + join(__dirname, 'testscript.ts'), + ]); - const npxOutput = npx.output.toString(); - const containsError = npxOutput.includes('error TS'); - if (expectSuccess) { - expect(containsError).toBeFalsy(); - } else { - expect(containsError).toBeTruthy(); - } - } - ); + const npxOutput = npx.output.toString(); + const containsError = npxOutput.includes('error TS'); + if (expectSuccess) { + expect(containsError).toBeFalsy(); + } else { + expect(containsError).toBeTruthy(); + } + } + ); });