Skip to content

Commit d87159b

Browse files
Fix duplicated test setupFiles in resolved vite config (#183)
* fix * format
1 parent 4d53941 commit d87159b

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/index.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,29 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
210210
? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h']
211211
: [];
212212

213-
const test = (userConfig as any).test || {};
214-
213+
const userTest = (userConfig as any) ?? {};
214+
const test = {} as any;
215215
if (userConfig.mode === 'test') {
216216
// to simplify the processing of the config, we normalize the setupFiles to an array
217217
const userSetupFiles: string[] =
218-
typeof test.setupFiles === 'string' ? [test.setupFiles] : test.setupFiles || [];
218+
typeof userTest.setupFiles === 'string'
219+
? [userTest.setupFiles]
220+
: userTest.setupFiles || [];
219221

220-
if (!test.environment && !options.ssr) {
222+
if (!userTest.environment && !options.ssr) {
221223
test.environment = 'jsdom';
222224
}
223225

224-
test.server = test.server || {};
225-
test.server.deps = test.server.deps || {};
226-
if (!test.server.deps.external?.find((item: string | RegExp) => /solid-js/.test(item.toString()))) {
227-
test.server.deps.external = [...(test.server.deps.external || []), /solid-js/];
226+
if (
227+
!userTest.server?.deps?.external?.find((item: string | RegExp) =>
228+
/solid-js/.test(item.toString()),
229+
)
230+
) {
231+
test.server = { deps: { external: [/solid-js/] } };
228232
}
229-
230233
const jestDomImport = getJestDomExport(userSetupFiles);
231234
if (jestDomImport) {
232-
test.setupFiles = [...userSetupFiles, jestDomImport];
235+
test.setupFiles = [jestDomImport];
233236
}
234237
}
235238

@@ -303,7 +306,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
303306
);
304307

305308
if (!filter(id)) {
306-
return null
309+
return null;
307310
}
308311

309312
id = id.replace(/\?.*$/, '');
@@ -327,17 +330,21 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
327330
}
328331

329332
// We need to know if the current file extension has a typescript options tied to it
330-
const shouldBeProcessedWithTypescript = /\.[mc]?tsx$/i.test(id) || extensionsToWatch.some((extension) => {
331-
if (typeof extension === 'string') {
332-
return extension.includes('tsx');
333-
}
333+
const shouldBeProcessedWithTypescript =
334+
/\.[mc]?tsx$/i.test(id) ||
335+
extensionsToWatch.some((extension) => {
336+
if (typeof extension === 'string') {
337+
return extension.includes('tsx');
338+
}
334339

335-
const [extensionName, extensionOptions] = extension;
336-
if (extensionName !== currentFileExtension) return false;
340+
const [extensionName, extensionOptions] = extension;
341+
if (extensionName !== currentFileExtension) return false;
337342

338-
return extensionOptions.typescript;
339-
});
340-
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = ['jsx']
343+
return extensionOptions.typescript;
344+
});
345+
const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = [
346+
'jsx',
347+
];
341348

342349
if (shouldBeProcessedWithTypescript) {
343350
plugins.push('typescript');

0 commit comments

Comments
 (0)