Skip to content

Commit

Permalink
test: support testing transpiled code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cjihrig committed Dec 19, 2024
1 parent 722b826 commit afea770
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/attach_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/cp_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/exec_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions src/test/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/test/match-buffer.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tsconfig-with-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": []
}

0 comments on commit afea770

Please sign in to comment.