From afea770ed1f6f0f70ce7711534ae170131d51354 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 19 Dec 2024 16:02:09 -0500 Subject: [PATCH] test: support testing transpiled code This commit makes it possible to execute the tests after transpilation. This should provide additional confidence that the code shipped to npm works as intended. --- package.json | 2 ++ src/attach_test.ts | 2 +- src/config_test.ts | 2 +- src/cp_test.ts | 2 +- src/exec_test.ts | 2 +- src/test/index.ts | 6 +++--- src/test/match-buffer.ts | 2 +- tsconfig-with-tests.json | 4 ++++ 8 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 tsconfig-with-tests.json diff --git a/package.json b/package.json index c7f3b00e9d..239b81a941 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,11 @@ "lint": "tslint --project \".\" && prettier --check \"./src/**/*.ts\" && tslint --project \"./examples/typescript\"", "clean": "rm -Rf node_modules/ dist/", "build": "tsc", + "build-with-tests": "tsc --project tsconfig-with-tests.json && cp 'src/test/echo space.js' dist/test", "generate": "./generate-client.sh", "watch": "tsc --watch", "test": "c8 mocha", + "test-transpiled": "mocha --no-config dist", "prepare": "npm run build && husky", "prepack": "npm run build", "docs": "typedoc src/gen/api" diff --git a/src/attach_test.ts b/src/attach_test.ts index 5d64d111b0..57a6d53207 100644 --- a/src/attach_test.ts +++ b/src/attach_test.ts @@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws'; import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers'; import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito'; -import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test'; +import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test/index.js'; import { Attach } from './attach.js'; import { KubeConfig } from './config.js'; import { TerminalSize } from './terminal-size-queue.js'; diff --git a/src/config_test.ts b/src/config_test.ts index 5af5326071..40f70fafbe 100644 --- a/src/config_test.ts +++ b/src/config_test.ts @@ -10,7 +10,7 @@ import mockfs from 'mock-fs'; import { Headers } from 'node-fetch'; import { HttpMethod } from './index.js'; -import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer'; +import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer.js'; import { CoreV1Api, RequestContext } from './api.js'; import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config.js'; import { ActionOnInvalid, Cluster, newClusters, newContexts, newUsers, User } from './config_types.js'; diff --git a/src/cp_test.ts b/src/cp_test.ts index eeee0342f0..104553c9bf 100644 --- a/src/cp_test.ts +++ b/src/cp_test.ts @@ -2,7 +2,7 @@ import { anything, anyFunction, instance, mock, verify, when } from 'ts-mockito' import querystring from 'node:querystring'; import WebSocket from 'isomorphic-ws'; -import { CallAwaiter } from './test'; +import { CallAwaiter } from './test/index.js'; import { KubeConfig } from './config.js'; import { Exec } from './exec.js'; import { Cp } from './cp.js'; diff --git a/src/exec_test.ts b/src/exec_test.ts index a5e7ab1b1f..c4d20769c6 100644 --- a/src/exec_test.ts +++ b/src/exec_test.ts @@ -3,7 +3,7 @@ import WebSocket from 'isomorphic-ws'; import { ReadableStreamBuffer, WritableStreamBuffer } from 'stream-buffers'; import { anyFunction, anything, capture, instance, mock, verify, when } from 'ts-mockito'; -import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test'; +import { CallAwaiter, matchBuffer, ResizableWriteableStreamBuffer } from './test/index.js'; import { V1Status } from './api.js'; import { KubeConfig } from './config.js'; import { Exec } from './exec.js'; diff --git a/src/test/index.ts b/src/test/index.ts index 66d899cea9..357ff538db 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -1,3 +1,3 @@ -export * from './call-awaiter'; -export * from './match-buffer'; -export * from './resizable-writeable-stream-buffer'; +export * from './call-awaiter.js'; +export * from './match-buffer.js'; +export * from './resizable-writeable-stream-buffer.js'; diff --git a/src/test/match-buffer.ts b/src/test/match-buffer.ts index a48bf8f1f7..e468fb56bf 100644 --- a/src/test/match-buffer.ts +++ b/src/test/match-buffer.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import { RequestOptions, Agent } from 'node:https'; -import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher'; +import { Matcher } from 'ts-mockito/lib/matcher/type/Matcher.js'; export function matchBuffer(channel: number, contents: string): StringBufferMatcher { return new StringBufferMatcher(channel, contents); diff --git a/tsconfig-with-tests.json b/tsconfig-with-tests.json new file mode 100644 index 0000000000..98928a3edd --- /dev/null +++ b/tsconfig-with-tests.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": [] +}