Skip to content

Commit 4ca9f18

Browse files
test/TRI 887/setup jest on cli package (#326)
* chore: run `pnpm install --prefer-frozen-lockfile` * chore: install `jest` and `ts-jest` * test: create `jest.config.js` * chore: install `@types/jest` * chore: add `jest` on `tsconfig.json` `types` property * chore: create test script * test: create example test 🎉🎊🕺🏼 * chore: install `@gmrchk/cli-testing-library` * chore: override `tsconfig` with `@trigger.dev/tsconfig` * test: make poc of cli test * chore: run build before test * docs: improve comment * Added a changeset --------- Co-authored-by: Matt Aitken <[email protected]>
1 parent 5dec3ed commit 4ca9f18

File tree

7 files changed

+678
-88
lines changed

7 files changed

+678
-88
lines changed

.changeset/lemon-clocks-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli": patch
3+
---
4+
5+
Added tests to the CLI, updated tsconfig file accordingly

packages/cli/jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
export default {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testMatch: ["<rootDir>/test/**/*.ts?(x)", "<rootDir>/test/**/?(*.)+(spec|test).ts?(x)"],
6+
};

packages/cli/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@
3535
"trigger-cli": "./dist/index.js"
3636
},
3737
"devDependencies": {
38+
"@trigger.dev/tsconfig": "workspace:*",
39+
"@gmrchk/cli-testing-library": "^0.1.2",
3840
"@types/gradient-string": "^1.1.2",
3941
"@types/inquirer": "^9.0.3",
42+
"@types/jest": "^29.5.3",
4043
"@types/node": "16",
4144
"@types/node-fetch": "^2.6.2",
45+
"jest": "^29.6.2",
4246
"rimraf": "^3.0.2",
47+
"ts-jest": "^29.1.1",
4348
"tsup": "^6.5.0",
4449
"type-fest": "^3.6.0",
4550
"typescript": "^4.9.5"
@@ -49,7 +54,8 @@
4954
"build": "tsup",
5055
"dev": "tsup --watch",
5156
"clean": "rimraf dist",
52-
"start": "node dist/index.js"
57+
"start": "node dist/index.js",
58+
"test": "jest"
5359
},
5460
"dependencies": {
5561
"@types/degit": "^2.8.3",

packages/cli/test/example.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { prepareEnvironment } from "@gmrchk/cli-testing-library";
2+
import { CLITestEnvironment } from "@gmrchk/cli-testing-library/lib/types";
3+
import { join } from "node:path";
4+
5+
let environment: CLITestEnvironment;
6+
7+
beforeAll(async () => {
8+
// This will create a sandbox folder under `/var/folders`
9+
environment = await prepareEnvironment();
10+
});
11+
12+
afterAll(async () => {
13+
await environment.cleanup();
14+
});
15+
16+
describe('cli', () => {
17+
// can be any path with a nextjs project
18+
const NEXT_PROJECT_PATH = join(__dirname, '..', '..', '..', 'examples', 'nextjs-example');
19+
20+
it('should be able to execute cli', async () => {
21+
const { waitForText, getStdout, wait, pressKey } = await environment.spawn('node', `${join(__dirname, '..', 'dist', 'index.js')} init -p ${NEXT_PROJECT_PATH}`)
22+
23+
console.log('getStdout() :>> ', getStdout());
24+
25+
await waitForText('Detected Next.js project');
26+
27+
console.log('getStdout() :>> ', getStdout());
28+
29+
await waitForText('Are you using the Trigger.dev cloud or self-hosted?');
30+
31+
console.log('getStdout() :>> ', getStdout());
32+
33+
await pressKey('enter');
34+
35+
console.log('getStdout() :>> ', getStdout());
36+
37+
// wait next prompt, make assertions and keep going
38+
});
39+
})

packages/cli/tsconfig.json

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,12 @@
11
{
2-
"include": ["src", "tsup.config.ts"],
2+
"extends": "@trigger.dev/tsconfig/node18.json",
3+
"include": ["src/globals.d.ts", "./src/**/*.ts", "tsup.config.ts", "./test/**/*.ts"],
34
"compilerOptions": {
4-
/* LANGUAGE COMPILATION OPTIONS */
5-
"target": "ES2020",
6-
"lib": ["DOM", "DOM.Iterable", "ES2020"],
7-
"module": "Node16",
8-
"moduleResolution": "nodenext",
9-
"resolveJsonModule": true,
10-
"allowJs": true,
11-
"checkJs": true,
12-
13-
/* EMIT RULES */
14-
"outDir": "./dist",
15-
"noEmit": true, // TSUP takes care of emitting js for us, in a MUCH faster way
16-
"declaration": true,
17-
"declarationMap": true,
18-
"sourceMap": true,
19-
"removeComments": true,
20-
21-
/* TYPE CHECKING RULES */
22-
"strict": true,
23-
// "noImplicitAny": true, // Included in "Strict"
24-
// "noImplicitThis": true, // Included in "Strict"
25-
// "strictBindCallApply": true, // Included in "Strict"
26-
// "strictFunctionTypes": true, // Included in "Strict"
27-
// "strictNullChecks": true, // Included in "Strict"
28-
// "strictPropertyInitialization": true, // Included in "Strict"
29-
"noFallthroughCasesInSwitch": true,
30-
"noImplicitOverride": true,
31-
"noImplicitReturns": true,
32-
"noUnusedLocals": true,
33-
"noUnusedParameters": true,
34-
"useUnknownInCatchVariables": true,
35-
"noUncheckedIndexedAccess": true, // TLDR - Checking an indexed value (array[0]) now forces type <T | undefined> as there is no confirmation that index exists
36-
// THE BELOW ARE EXTRA STRICT OPTIONS THAT SHOULD ONLY BY CONSIDERED IN VERY SAFE PROJECTS
37-
// "exactOptionalPropertyTypes": true, // TLDR - Setting to undefined is not the same as a property not being defined at all
38-
// "noPropertyAccessFromIndexSignature": true, // TLDR - Use dot notation for objects if youre sure it exists, use ['index'] notaion if unsure
39-
40-
/* OTHER OPTIONS */
41-
"allowSyntheticDefaultImports": true,
42-
"esModuleInterop": true,
43-
// "emitDecoratorMetadata": true,
44-
// "experimentalDecorators": true,
45-
"forceConsistentCasingInFileNames": true,
46-
"skipLibCheck": true,
47-
"useDefineForClassFields": true
48-
}
5+
"experimentalDecorators": true,
6+
"emitDecoratorMetadata": true,
7+
"declaration": false,
8+
"declarationMap": false,
9+
"types": ["jest"]
10+
},
11+
"exclude": ["node_modules"]
4912
}

0 commit comments

Comments
 (0)