From 9d985b3dee160635e678825bfa547b236fccc730 Mon Sep 17 00:00:00 2001 From: Craig Spence Date: Thu, 17 Jun 2021 18:09:32 +0200 Subject: [PATCH] =?UTF-8?q?feat(betterer=20=E2=9C=A8):=20enable=20CI=20mod?= =?UTF-8?q?e=20when=20CI=20env=20variable=20is=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/cli/src/options.ts | 2 + packages/cli/src/start.ts | 5 + .../__snapshots__/betterer-ci.spec.ts.snap | 151 ++++++++++++++++++ test/cli/betterer-ci.spec.ts | 52 +++++- 4 files changed, 209 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/options.ts b/packages/cli/src/options.ts index 401645b6c..d51abf17b 100644 --- a/packages/cli/src/options.ts +++ b/packages/cli/src/options.ts @@ -9,11 +9,13 @@ import { } from './types'; export function ciOptions(argv: BettererCLIArguments): BettererCLICIConfig { + cacheOption(); // Ignored configPathsOption(); resultsPathOption(); tsconfigPathOption(); filtersOption(); silentOption(); + strictOption(); // Ignored reportersOption(); excludesOption(); const options = setEnv(argv); diff --git a/packages/cli/src/start.ts b/packages/cli/src/start.ts index 10efbc782..fa404e802 100644 --- a/packages/cli/src/start.ts +++ b/packages/cli/src/start.ts @@ -1,10 +1,15 @@ import { BettererSummary, betterer, BettererOptionsStart } from '@betterer/betterer'; +import { ciΞ” } from './ci'; import { startOptions } from './options'; import { BettererCLIArguments } from './types'; /** @internal Definitely not stable! Please don't use! */ export function startΞ”(cwd: string, argv: BettererCLIArguments): Promise { + if (process.env.CI) { + return ciΞ”(cwd, argv); + } + const { cache, cachePath, diff --git a/test/cli/__snapshots__/betterer-ci.spec.ts.snap b/test/cli/__snapshots__/betterer-ci.spec.ts.snap index 7c4ca60f9..144e044c6 100644 --- a/test/cli/__snapshots__/betterer-ci.spec.ts.snap +++ b/test/cli/__snapshots__/betterer-ci.spec.ts.snap @@ -381,6 +381,157 @@ Error: \\"typescript use strict mode\\" got worse. (1 new issue, 2 total) πŸ˜” 1 test got worse. πŸ˜” +", +] +`; + +exports[`betterer ci should work with \`start\` and the CI env variable 1`] = ` +Array [ + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): 1 test running... +πŸ€” typescript use strict mode: running \\"typescript use strict mode\\"! + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): 1 test running... +βœ… typescript use strict mode: \\"typescript use strict mode\\" got checked for the first time! (1 issue) πŸŽ‰ + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +πŸŽ‰ Betterer (0ms): 1 test done! +βœ… typescript use strict mode: \\"typescript use strict mode\\" got checked for the first time! (1 issue) πŸŽ‰ + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +πŸŽ‰ Betterer (0ms): 1 test done! +βœ… typescript use strict mode: \\"typescript use strict mode\\" got checked for the first time! (1 issue) πŸŽ‰ + +1 test got checked. πŸ€” +1 test got checked for the first time! πŸŽ‰ + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): 1 test running... +πŸ€” typescript use strict mode: running \\"typescript use strict mode\\"! + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +🌟 Betterer (0ms): 1 test running... +βœ… typescript use strict mode: \\"typescript use strict mode\\" stayed the same. (1 issue) 😐 + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +πŸŽ‰ Betterer (0ms): 1 test done! +βœ… typescript use strict mode: \\"typescript use strict mode\\" stayed the same. (1 issue) 😐 + +", + " + / | / _ _ _ + '-.ooo.-' | |__ ___| |_| |_ ___ _ __ ___ _ __ +---ooooo--- | '_ // _ / __| __/ _ / '__/ _ / '__| + .-'ooo'-. | |_)| __/ |_| || __/ | | __/ | + / | / |_.__//___|/__|/__/___|_| /___|_| + +πŸŽ‰ Betterer (0ms): 1 test done! +βœ… typescript use strict mode: \\"typescript use strict mode\\" stayed the same. (1 issue) 😐 + +1 test got checked. πŸ€” +1 test stayed the same. 😐 + +Unexpected diff found: +- Expected ++ Result + + // BETTERER RESULTS V2. + exports[\`typescript use strict mode\`] = { + value: \`{ +- \\"src/index.ts:1499252024\\": [ +- [2, 12, 1, \\"The left-hand side of an arithmetic operation must be of type /'any/', /'number/', /'bigint/' or an enum type.\\", \\"177604\\"] ++ \\"src/index.ts:2615232350\\": [ ++ [3, 12, 1, \\"The left-hand side of an arithmetic operation must be of type /'any/', /'number/', /'bigint/' or an enum type.\\", \\"177604\\"] + ] + }\` + }; + + ", ] `; diff --git a/test/cli/betterer-ci.spec.ts b/test/cli/betterer-ci.spec.ts index ad2046912..3278649b4 100644 --- a/test/cli/betterer-ci.spec.ts +++ b/test/cli/betterer-ci.spec.ts @@ -1,4 +1,4 @@ -import { ciΞ” } from '@betterer/cli'; +import { ciΞ”, startΞ” } from '@betterer/cli'; import { createFixture } from '../fixture'; @@ -53,6 +53,56 @@ export default { await cleanup(); }); + it('should work with `start` and the CI env variable', async () => { + const { paths, logs, cleanup, resolve, writeFile } = await createFixture('test-betterer-ci-start', { + 'src/index.ts': ` +const a = 'a'; +const one = 1; +console.log(a * one); + `, + '.betterer.ts': ` +import { typescript } from '@betterer/typescript'; + +export default { + 'typescript use strict mode': typescript('./tsconfig.json', { + strict: true + }) +}; + `, + 'tsconfig.json': ` +{ + "compilerOptions": { + "noEmit": true, + "lib": ["esnext"], + "moduleResolution": "node", + "target": "ES5", + "typeRoots": ["../../node_modules/@types/"], + "resolveJsonModule": true + }, + "include": ["./src/**/*", ".betterer.ts"] +} + ` + }); + + const fixturePath = paths.cwd; + const indexPath = resolve('./src/index.ts'); + + process.env.CI = '1'; + + await startΞ”(fixturePath, ARGV); + + await writeFile(indexPath, `const a = 'a';\nconst one = 1;\nconsole.log(one + one);\nconsole.log(a * one);`); + + const diffSummary = await startΞ”(fixturePath, ARGV); + + expect(diffSummary.expected).not.toBeNull(); + expect(diffSummary.unexpectedDiff).toEqual(true); + expect(diffSummary.worse).toHaveLength(0); + + expect(logs).toMatchSnapshot(); + + await cleanup(); + }); it('should work when a test gets worse', async () => { const { paths, logs, cleanup, resolve, writeFile } = await createFixture('test-betterer-ci-worse', {