Skip to content

Commit 94d48fb

Browse files
committed
refactor: wip
1 parent 0915501 commit 94d48fb

4 files changed

Lines changed: 53 additions & 53 deletions

File tree

e2e/plugin-knip-e2e/tests/knip-reporter.e2e.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ describe('knip reporter for code pushup audits', () => {
4444
'knip',
4545
'--no-exit-code',
4646
`--reporter=${reporterPath}`,
47-
/* eslint-disable-next-line unicorn/prefer-string-raw */
48-
`--reporter-options={\\"outputFile\\":\\"knip-report.json\\"}`,
47+
`--reporter-options=${JSON.stringify(JSON.stringify({ outputFile: 'knip-report.json' }))}`,
4948
],
5049
cwd: reporterSetupDir,
5150
});
@@ -66,7 +65,7 @@ describe('knip reporter for code pushup audits', () => {
6665
message: 'Unused dependency zod',
6766
severity: 'error',
6867
source: {
69-
file: expect.stringContaining('package.json'),
68+
file: expect.pathToEndWith('package.json'),
7069
position: {
7170
startColumn: 6,
7271
startLine: 4,

e2e/plugin-knip-e2e/tsconfig.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"vitest.e2e.config.ts",
1010
"tests/**/*.e2e.test.ts",
1111
"tests/**/*.d.ts",
12-
"mocks/**/*.ts"
12+
"mocks/**/*.ts",
13+
"../../testing/test-setup/src/vitest.d.ts"
1314
]
1415
}

packages/plugin-knip/src/lib/reporter/reporter.unit.test.ts

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -123,60 +123,59 @@ describe('knipReporter', () => {
123123
'jsonc-eslint-parser': {
124124
type: 'unlisted',
125125
symbol: 'jsonc-eslint-parser',
126-
filePath: expect.stringContaining('package.json')
126+
filePath: expect.pathToEndWith('package.json')
127127
},
128128
},
129129
});
130130
expect(rawKnipReport.counters).toStrictEqual({files: 1, unlisted: 1});
131131
});
132-
});
133132

134-
it('should log if custom reporter option verbose is true', async () => {
135-
const reporterOptions: CustomReporterOptions = {
136-
verbose: true,
137-
outputFile: KNIP_REPORT_NAME,
138-
rawOutputFile: KNIP_RAW_REPORT_NAME,
139-
};
140-
await expect(
141-
knipReporter({
142-
report: {files: true},
143-
issues: {files: new Set(['main.js'])},
144-
options: JSON.stringify(reporterOptions),
145-
} as ReporterOptions),
146-
).resolves.toBeUndefined();
147-
148-
expect(logger.info).toHaveBeenCalledTimes(3);
149-
expect(logger.info).toHaveBeenNthCalledWith(
150-
1,
151-
`Reporter called with options: ${JSON.stringify(
152-
reporterOptions,
153-
null,
133+
it('should log if custom reporter option verbose is true', async () => {
134+
const reporterOptions: CustomReporterOptions = {
135+
verbose: true,
136+
outputFile: KNIP_REPORT_NAME,
137+
rawOutputFile: KNIP_RAW_REPORT_NAME,
138+
};
139+
await expect(
140+
knipReporter({
141+
report: {files: true},
142+
issues: {files: new Set(['main.js'])},
143+
options: JSON.stringify(reporterOptions),
144+
} as ReporterOptions),
145+
).resolves.toBeUndefined();
146+
147+
expect(logger.info).toHaveBeenCalledTimes(3);
148+
expect(logger.info).toHaveBeenNthCalledWith(
149+
1,
150+
`Reporter called with options: ${JSON.stringify(
151+
reporterOptions,
152+
null,
153+
2,
154+
)}`,
155+
);
156+
expect(logger.info).toHaveBeenNthCalledWith(
154157
2,
155-
)}`,
156-
);
157-
expect(logger.info).toHaveBeenNthCalledWith(
158-
2,
159-
`Saved raw report to ${reporterOptions.rawOutputFile}`,
160-
);
161-
expect(logger.info).toHaveBeenNthCalledWith(
162-
3,
163-
`Saved report to ${reporterOptions.outputFile}`,
164-
);
165-
});
158+
`Saved raw report to ${reporterOptions.rawOutputFile}`,
159+
);
160+
expect(logger.info).toHaveBeenNthCalledWith(
161+
3,
162+
`Saved report to ${reporterOptions.outputFile}`,
163+
);
164+
});
166165

167-
it('should produce valid audit outputs', async () => {
168-
await expect(
169-
knipReporter(rawReport as ReporterOptions),
170-
).resolves.toBeUndefined();
171-
172-
const auditOutputsContent = await memfsFs.promises.readFile(
173-
'knip-report.json',
174-
{encoding: 'utf8'},
175-
);
176-
const auditOutputsJson = JSON.parse(
177-
auditOutputsContent.toString(),
178-
) as AuditOutputs;
179-
expect(auditOutputsJson).toMatchSnapshot();
180-
});
166+
it('should produce valid audit outputs', async () => {
167+
await expect(
168+
knipReporter(rawReport as ReporterOptions),
169+
).resolves.toBeUndefined();
170+
171+
const auditOutputsContent = await memfsFs.promises.readFile(
172+
'knip-report.json',
173+
{encoding: 'utf8'},
174+
);
175+
const auditOutputsJson = JSON.parse(
176+
auditOutputsContent.toString(),
177+
) as AuditOutputs;
178+
expect(auditOutputsJson).toMatchSnapshot();
179+
})
181180
})
182-
;
181+

packages/plugin-knip/tsconfig.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"src/**/*.test.tsx",
1313
"src/**/*.test.js",
1414
"src/**/*.test.jsx",
15-
"src/**/*.d.ts"
15+
"src/**/*.d.ts",
16+
"../../testing/test-setup/src/vitest.d.ts"
1617
]
1718
}

0 commit comments

Comments
 (0)