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 <matt@mattaitken.com>
This commit is contained in:
Wesley
2023-08-16 18:35:23 -03:00
committed by GitHub
parent 5dec3ed4e6
commit 4ca9f182d7
7 changed files with 678 additions and 88 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/cli": patch
---
Added tests to the CLI, updated tsconfig file accordingly
+6
View File
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ["<rootDir>/test/**/*.ts?(x)", "<rootDir>/test/**/?(*.)+(spec|test).ts?(x)"],
};
+7 -1
View File
@@ -35,11 +35,16 @@
"trigger-cli": "./dist/index.js"
},
"devDependencies": {
"@trigger.dev/tsconfig": "workspace:*",
"@gmrchk/cli-testing-library": "^0.1.2",
"@types/gradient-string": "^1.1.2",
"@types/inquirer": "^9.0.3",
"@types/jest": "^29.5.3",
"@types/node": "16",
"@types/node-fetch": "^2.6.2",
"jest": "^29.6.2",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"tsup": "^6.5.0",
"type-fest": "^3.6.0",
"typescript": "^4.9.5"
@@ -49,7 +54,8 @@
"build": "tsup",
"dev": "tsup --watch",
"clean": "rimraf dist",
"start": "node dist/index.js"
"start": "node dist/index.js",
"test": "jest"
},
"dependencies": {
"@types/degit": "^2.8.3",
+39
View File
@@ -0,0 +1,39 @@
import { prepareEnvironment } from "@gmrchk/cli-testing-library";
import { CLITestEnvironment } from "@gmrchk/cli-testing-library/lib/types";
import { join } from "node:path";
let environment: CLITestEnvironment;
beforeAll(async () => {
// This will create a sandbox folder under `/var/folders`
environment = await prepareEnvironment();
});
afterAll(async () => {
await environment.cleanup();
});
describe('cli', () => {
// can be any path with a nextjs project
const NEXT_PROJECT_PATH = join(__dirname, '..', '..', '..', 'examples', 'nextjs-example');
it('should be able to execute cli', async () => {
const { waitForText, getStdout, wait, pressKey } = await environment.spawn('node', `${join(__dirname, '..', 'dist', 'index.js')} init -p ${NEXT_PROJECT_PATH}`)
console.log('getStdout() :>> ', getStdout());
await waitForText('Detected Next.js project');
console.log('getStdout() :>> ', getStdout());
await waitForText('Are you using the Trigger.dev cloud or self-hosted?');
console.log('getStdout() :>> ', getStdout());
await pressKey('enter');
console.log('getStdout() :>> ', getStdout());
// wait next prompt, make assertions and keep going
});
})
+9 -46
View File
@@ -1,49 +1,12 @@
{
"include": ["src", "tsup.config.ts"],
"extends": "@trigger.dev/tsconfig/node18.json",
"include": ["src/globals.d.ts", "./src/**/*.ts", "tsup.config.ts", "./test/**/*.ts"],
"compilerOptions": {
/* LANGUAGE COMPILATION OPTIONS */
"target": "ES2020",
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"module": "Node16",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
/* EMIT RULES */
"outDir": "./dist",
"noEmit": true, // TSUP takes care of emitting js for us, in a MUCH faster way
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"removeComments": true,
/* TYPE CHECKING RULES */
"strict": true,
// "noImplicitAny": true, // Included in "Strict"
// "noImplicitThis": true, // Included in "Strict"
// "strictBindCallApply": true, // Included in "Strict"
// "strictFunctionTypes": true, // Included in "Strict"
// "strictNullChecks": true, // Included in "Strict"
// "strictPropertyInitialization": true, // Included in "Strict"
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true, // TLDR - Checking an indexed value (array[0]) now forces type <T | undefined> as there is no confirmation that index exists
// THE BELOW ARE EXTRA STRICT OPTIONS THAT SHOULD ONLY BY CONSIDERED IN VERY SAFE PROJECTS
// "exactOptionalPropertyTypes": true, // TLDR - Setting to undefined is not the same as a property not being defined at all
// "noPropertyAccessFromIndexSignature": true, // TLDR - Use dot notation for objects if youre sure it exists, use ['index'] notaion if unsure
/* OTHER OPTIONS */
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
// "emitDecoratorMetadata": true,
// "experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"useDefineForClassFields": true
}
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": false,
"declarationMap": false,
"types": ["jest"]
},
"exclude": ["node_modules"]
}
+611 -41
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -46,6 +46,7 @@
"cache": false
},
"test": {
"dependsOn": ["^build"],
"outputs": []
},
"test:dev": {