Skip to content

Commit 17ea733

Browse files
committed
fix e2e
1 parent e812e3c commit 17ea733

File tree

16 files changed

+767
-106
lines changed

16 files changed

+767
-106
lines changed

e2e/plugin-typescript-e2e/tests/__snapshots__/typescript-plugin-json-report.json

Lines changed: 539 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Code PushUp CLI
2+
[ info ] Run collect...
3+
Code PushUp Report - @code-pushup/[email protected]
4+
5+
6+
Typescript audits
7+
8+
● AllowSyntheticDefaultImports 0
9+
● AllowUnreachableCode 0
10+
● AlwaysStrict 0
11+
● CustomConditions 0
12+
● DownlevelIteration 0
13+
● EmitBOM 0
14+
● EmitDeclarationOnly 0
15+
● EmitDecoratorMetadata 0
16+
● EsModuleInterop 0
17+
● ExactOptionalPropertyTypes 0
18+
● ExperimentalDecorators 0
19+
● ForceConsistentCasingInFileNames 0
20+
● ImportHelpers 0
21+
● IsolatedModules 0
22+
● Jsx 0
23+
● JsxFactory 0
24+
● JsxFragmentFactory 0
25+
● JsxImportSource 0
26+
● Lib 0
27+
● ModuleDetection 0
28+
● ModuleResolution 0
29+
● NoEmit 0
30+
● NoEmitHelpers 0
31+
● NoEmitOnError 0
32+
● NoFallthroughCasesInSwitch 0
33+
● NoImplicitAny 0
34+
● NoImplicitOverride 0
35+
● NoImplicitReturns 0
36+
● NoImplicitThis 0
37+
● NoLib 0
38+
● NoPropertyAccessFromIndexSignature 0
39+
● NoUncheckedIndexedAccess 0
40+
● PreserveConstEnums 0
41+
● PreserveSymlinks 0
42+
● ReactNamespace 0
43+
● RemoveComments 0
44+
● ResolvePackageJsonExports 0
45+
● ResolvePackageJsonImports 0
46+
● StrictBindCallApply 0
47+
● StrictBuiltinIteratorReturn 0
48+
● StrictFunctionTypes 0
49+
● StrictNullChecks 0
50+
● StrictPropertyInitialization 0
51+
● StripInternal 0
52+
● Target 0
53+
● UseDefineForClassFields 0
54+
● VerbatimModuleSyntax 0
55+
56+
Categories
57+
58+
┌─────────────────────────────────────────────────────────┬─────────┬──────────┐
59+
│ Category │ Score │ Audits │
60+
├─────────────────────────────────────────────────────────┼─────────┼──────────┤
61+
│ Typescript │ 100 │ 47 │
62+
└─────────────────────────────────────────────────────────┴─────────┴──────────┘
63+
64+
Made with ❤ by code-pushup.dev
65+
66+
[ success ] Generated reports successfully:
67+
[ success ] - __test__/create-report/.code-pushup/report.json (19.08 kB)
68+
[ success ] - __test__/create-report/.code-pushup/report.md (10.5 kB)
69+
[ success ] Collecting report successful!
70+
╭────────────────────────────────────────────────────────────────────────────────────────────╮
71+
│ │
72+
│ 💡 Visualize your reports │
73+
│ │
74+
│ ❯ npx code-pushup upload - Run upload to upload the created report to the server │
75+
│ https://github.com/code-pushup/cli/tree/main/packages/cli#upload-command │
76+
│ ❯ npx code-pushup autorun - Run collect & upload │
77+
│ https://github.com/code-pushup/cli/tree/main/packages/cli#autorun-command │
78+
│ │
79+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cp } from 'node:fs/promises';
22
// eslint-disable-next-line unicorn/import-style
3-
import { join } from 'node:path';
3+
import path, { join } from 'node:path';
44
import { afterAll, beforeAll, expect } from 'vitest';
55
import { type Report, reportSchema } from '@code-pushup/models';
66
import { nxTargetProject } from '@code-pushup/test-nx-utils';
@@ -13,48 +13,58 @@ import {
1313
} from '@code-pushup/test-utils';
1414
import { executeProcess, readJsonFile } from '@code-pushup/utils';
1515

16-
describe.todo(
17-
'PLUGIN collect report with typescript-plugin NPM package',
18-
() => {
19-
const envRoot = join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
20-
const testFileDir = join(envRoot, TEST_OUTPUT_DIR, 'collect');
21-
const defaultSetupDir = join(testFileDir, 'default-setup');
16+
describe('PLUGIN collect report with typescript-plugin NPM package', () => {
17+
const envRoot = join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
18+
const distRoot = join(envRoot, TEST_OUTPUT_DIR);
2219

23-
const fixturesDir = join('e2e', nxTargetProject(), 'mocks', 'fixtures');
20+
const fixturesDir = join(
21+
'e2e',
22+
nxTargetProject(),
23+
'mocks',
24+
'fixtures',
25+
'default-setup',
26+
);
2427

25-
beforeAll(async () => {
26-
await cp(fixturesDir, testFileDir, { recursive: true });
27-
});
28+
beforeAll(async () => {
29+
await cp(fixturesDir, envRoot, { recursive: true });
30+
});
2831

29-
afterAll(async () => {
30-
await teardownTestFolder(testFileDir);
31-
});
32+
afterAll(async () => {
33+
await teardownTestFolder(distRoot);
34+
});
35+
36+
it('should run plugin over CLI and creates report.json', async () => {
37+
const outputDir = join(
38+
path.relative(envRoot, distRoot),
39+
'create-report',
40+
'.code-pushup',
41+
);
3242

33-
it('should run plugin over CLI and creates report.json', async () => {
34-
const { code, stdout } = await executeProcess({
35-
command: 'npx',
36-
// verbose exposes audits with perfect scores that are hidden in the default stdout
37-
args: [
38-
'@code-pushup/cli',
39-
'collect',
40-
`--config=${join(TEST_OUTPUT_DIR, 'collect', 'default-setup', 'code-pushup.config.ts')}`,
41-
'--no-progress',
42-
'--verbose',
43-
],
44-
cwd: envRoot,
45-
});
46-
47-
expect(code).toBe(0);
48-
const cleanStdout = removeColorCodes(stdout);
49-
expect(cleanStdout).toContain('● Largest Contentful Paint');
50-
51-
const report = await readJsonFile(
52-
join(defaultSetupDir, '.code-pushup', 'report.json'),
53-
);
54-
expect(() => reportSchema.parse(report)).not.toThrow();
55-
expect(
56-
omitVariableReportData(report as Report, { omitAuditData: true }),
57-
).toMatchSnapshot();
43+
const { code, stdout } = await executeProcess({
44+
command: 'npx',
45+
// verbose exposes audits with perfect scores that are hidden in the default stdout
46+
args: [
47+
'@code-pushup/cli',
48+
'collect',
49+
'--no-progress',
50+
'--verbose',
51+
`--persist.outputDir=${outputDir}`,
52+
],
53+
cwd: envRoot,
5854
});
59-
},
60-
);
55+
56+
expect(code).toBe(0);
57+
const cleanStdout = removeColorCodes(stdout);
58+
expect(cleanStdout).toMatchFileSnapshot(
59+
'__snapshots__/typescript-plugin-terminal-report.txt',
60+
);
61+
62+
expect(cleanStdout).toMatch(/ NoImplicitAny\s+1/);
63+
64+
const report = await readJsonFile(join(envRoot, outputDir, 'report.json'));
65+
expect(() => reportSchema.parse(report)).not.toThrow();
66+
expect(
67+
omitVariableReportData(report as Report, { omitAuditData: true }),
68+
).toMatchFileSnapshot('__snapshots__/typescript-plugin-json-report.json');
69+
});
70+
});

e2e/plugin-typescript-e2e/tests/install.e2e.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import path from 'node:path';
33
import { expect } from 'vitest';
44
import { nxTargetProject } from '@code-pushup/test-nx-utils';
55
import { E2E_ENVIRONMENTS_DIR } from '@code-pushup/test-utils';
6-
import { getCurrentTsVersion } from '@code-pushup/typescript-plugin';
6+
import {
7+
getCurrentTsVersion,
8+
getTsDefaultsFilename,
9+
} from '@code-pushup/typescript-plugin';
710

811
describe('PLUGIN install of typescript-plugin NPM package', () => {
912
const envRoot = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
@@ -17,7 +20,11 @@ describe('PLUGIN install of typescript-plugin NPM package', () => {
1720
it('should have current TS version defaults generated after install', async () => {
1821
await expect(
1922
readFile(
20-
path.join(envRoot, cacheDir, `${await getCurrentTsVersion()}.ts`),
23+
path.join(
24+
envRoot,
25+
cacheDir,
26+
getTsDefaultsFilename(await getCurrentTsVersion()),
27+
),
2128
),
2229
).resolves.not.toThrow();
2330
});

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"prepare": "husky install",
1717
"commit": "git-cz",
1818
"knip": "knip",
19-
"postinstall-plugin-typescript": "npx tsx --tsconfig=packages/plugin-typescript/tsconfig.lib.json packages/plugin-typescript/src/postinstall/index.ts",
20-
"postinstall": "npm run postinstall-plugin-typescript"
19+
"postinstall": "npx nx run plugin-typescript:postinstall"
2120
},
2221
"private": true,
2322
"engines": {

packages/plugin-typescript/mocks/fixtures/default-ts-configs/5.5.4.ts renamed to packages/plugin-typescript/mocks/fixtures/default-ts-configs/5.5.4.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const config = {
1+
{
22
"compilerOptions": {
33
"incremental": true,
44
"composite": true,
@@ -88,5 +88,4 @@ const config = {
8888
"skipDefaultLibCheck": true,
8989
"skipLibCheck": true
9090
}
91-
}
92-
export default config;
91+
}

packages/plugin-typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
"@code-pushup/utils": "0.57.0"
3030
},
3131
"scripts": {
32-
"postinstall": "node ./src/postinstall/index.js"
32+
"postinstall": "node ./src/postinstall/bin.js"
3333
}
3434
}

packages/plugin-typescript/project.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
}
3838
},
3939
"postinstall": {
40-
"command": "npx tsx --tsconfig=packages/plugin-typescript/tsconfig.lib.json packages/plugin-typescript/src/postinstall/index.ts"
40+
"dependsOn": ["build"],
41+
"command": "npx tsx --tsconfig packages/plugin-typescript/tsconfig.lib.json packages/plugin-typescript/src/postinstall/create.bin.ts",
42+
"cwd": ""
4143
}
4244
},
4345
"tags": ["scope:plugin", "type:feature", "publishable"]

packages/plugin-typescript/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { getCurrentTsVersion } from './lib/runner/utils.js';
77
export { getCategoryRefsFromGroups } from './lib/utils.js';
88
export { typescriptPlugin } from './lib/typescript-plugin.js';
99
export default typescriptPlugin;
10+
export { getTsDefaultsFilename } from './lib/runner/constants.js';

packages/plugin-typescript/src/lib/constants.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// eslint-disable-next-line unicorn/import-style
2-
import { join } from 'node:path';
32
import type { Audit, Group } from '@code-pushup/models';
43
import { camelCaseToKebabCase, kebabCaseToSentence } from '@code-pushup/utils';
54
import { TS_ERROR_CODES } from './runner/ts-error-codes.js';
65
import type { CompilerOptionName } from './runner/types.js';
76

8-
export const TS_PLUGIN_CACHE = join('.code-pushup', 'typescript-plugin');
9-
export const TS_CONFIG_DIR = join(TS_PLUGIN_CACHE, 'default-ts-configs');
10-
117
export const TYPESCRIPT_PLUGIN_SLUG = 'typescript';
128
export const DEFAULT_TS_CONFIG = 'tsconfig.json';
139

0 commit comments

Comments
 (0)