Skip to content

Commit 4092fa0

Browse files
committed
refactor unit tests
1 parent 396b761 commit 4092fa0

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"rootDir": "./src",
44
"strict": true,
5+
"verbatimModuleSyntax": false,
56
"target": "ES6",
67
"module": "CommonJSsss"
78
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ export async function normalizeCompilerOptions(
150150
});
151151
}
152152

153-
export function validateAudits(filteredAudits: Audit[]) {
153+
export function validateAudits(audits: Audit[]) {
154154
const skippedAudits = AUDITS.filter(
155-
audit => !filteredAudits.some(filtered => filtered.slug === audit.slug),
155+
audit => !audits.some(filtered => filtered.slug === audit.slug),
156156
).map(audit => kebabCaseToCamelCase(audit.slug));
157157
if (skippedAudits.length > 0) {
158158
console.warn(
159-
`Some audits were skipped because the configuration of the compiler options [${skippedAudits.join(', ')}]`,
159+
`Skipped audits because the compiler options disabled: [${skippedAudits.join(', ')}]`,
160160
);
161161
}
162162
}

packages/plugin-typescript/src/lib/utils.unit.test.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
filterAuditsByCompilerOptions,
77
filterAuditsBySlug,
88
handleCompilerOptionStrict,
9+
normalizeCompilerOptions,
910
validateAudits,
1011
} from './utils.js';
1112

@@ -93,17 +94,15 @@ describe('handleCompilerOptionStrict', () => {
9394
it('should return original options when strict is false', () => {
9495
const options: CompilerOptions = {
9596
strict: false,
96-
target: 2,
9797
};
9898

9999
const result = handleCompilerOptionStrict(options);
100-
expect(result).toB(options);
100+
expect(result).toBe(options);
101101
});
102102

103103
it('should add all strict options when strict is true', () => {
104104
const options: CompilerOptions = {
105105
strict: true,
106-
target: 2,
107106
};
108107

109108
const result = handleCompilerOptionStrict(options);
@@ -121,17 +120,29 @@ describe('handleCompilerOptionStrict', () => {
121120
});
122121
});
123122

123+
it('should add all strict options when strict is true and override existing value', () => {
124+
const options: CompilerOptions = {
125+
strict: true,
126+
noImplicitAny: false,
127+
};
128+
129+
const result = handleCompilerOptionStrict(options);
130+
131+
expect(result.noImplicitAny).toBe(true);
132+
});
133+
124134
it('should preserve existing option values while adding strict options', () => {
125135
const options: CompilerOptions = {
126136
strict: true,
127137
target: 2,
128-
noImplicitAny: false,
138+
verbatimModuleSyntax: false,
129139
};
130140

131141
const result = handleCompilerOptionStrict(options);
132142

143+
expect(result.strict).toBe(true);
133144
expect(result.target).toBe(2);
134-
expect(result.noImplicitAny).toBe(true);
145+
expect(result.verbatimModuleSyntax).toBe(false);
135146
});
136147
});
137148

@@ -147,23 +158,28 @@ describe('validateAudits', () => {
147158
});
148159

149160
it('should not warn when all audits are included', () => {
150-
const filteredAudits = AUDITS.map(audit => ({ ...audit }));
151-
152-
validateAudits(filteredAudits);
161+
validateAudits(AUDITS);
153162

154163
expect(console.warn).not.toHaveBeenCalled();
155164
});
156165

157166
it('should warn about skipped audits', () => {
158-
const filteredAudits = AUDITS.slice(1); // Removes an audit
159-
validateAudits(filteredAudits);
167+
validateAudits(AUDITS.slice(0, -1));
160168

161-
expect(console.warn).toHaveBeenCalled();
169+
expect(console.warn).toHaveBeenCalledTimes(1);
170+
expect(console.warn).toHaveBeenCalledWith(
171+
expect.stringContaining(
172+
`Skipped audits because the compiler options disabled: [`,
173+
),
174+
);
162175
});
163176

164-
it('should warn of all audits when filteredAudits are empty', () => {
165-
validateAudits([]);
177+
it('should camel case the slugs in the audit message', () => {
178+
validateAudits(AUDITS.slice(0, -1));
166179

167-
expect(console.warn).toHaveBeenCalled();
180+
expect(console.warn).toHaveBeenCalledTimes(1);
181+
expect(console.warn).toHaveBeenCalledWith(
182+
expect.stringContaining(`strictFunctionTypes`),
183+
);
168184
});
169185
});

0 commit comments

Comments
 (0)