Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(betterer ✨): enable CI mode when CI env variable is set #770

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cli/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BettererCLICIConfig>(argv);
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/start.ts
Original file line number Diff line number Diff line change
@@ -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<BettererSummary> {
if (process.env.CI) {
return ciΔ(cwd, argv);
}

const {
cache,
cachePath,
Expand Down
151 changes: 151 additions & 0 deletions test/cli/__snapshots__/betterer-ci.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"]
]
}\`
};


",
]
`;
52 changes: 51 additions & 1 deletion test/cli/betterer-ci.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ciΔ } from '@betterer/cli';
import { ciΔ, startΔ } from '@betterer/cli';

import { createFixture } from '../fixture';

Expand Down Expand Up @@ -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', {
Expand Down