Skip to content

Commit 01de70b

Browse files
author
Alex Lohr
committed
inline solid-js for testing, fix jest-dom detect
1 parent a381ec3 commit 01de70b

File tree

3 files changed

+141
-12
lines changed

3 files changed

+141
-12
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-solid",
3-
"version": "2.8.2",
3+
"version": "2.8.3",
44
"description": "solid-js integration plugin for vite 3/4/5",
55
"type": "module",
66
"files": [
@@ -65,8 +65,12 @@
6565
"vite": "^5.0.0"
6666
},
6767
"peerDependencies": {
68+
"@testing-library/jest-dom": "^5.16.6 || ^5.17.0 || ^6.*",
6869
"solid-js": "^1.7.2",
6970
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0"
7071
},
72+
"peerDependencyMeta": {
73+
"@testing-library/jest-dom": { "optional": true }
74+
},
7175
"packageManager": "[email protected]"
7276
}

pnpm-lock.yaml

Lines changed: 121 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,13 @@ function containsSolidField(fields: Record<string, any>) {
280280
}
281281

282282
function getJestDomExport(setupFiles: string[]) {
283-
return (setupFiles || []).some((path) => /jest-dom/.test(path))
283+
return setupFiles?.some((path) => /jest-dom/.test(path))
284284
? undefined
285285
: ['@testing-library/jest-dom/vitest', '@testing-library/jest-dom/extend-expect'].find(
286286
(path) => {
287287
try {
288-
require(path);
288+
require.resolve(path);
289+
return true;
289290
} catch (e) {
290291
return false;
291292
}
@@ -328,19 +329,24 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
328329

329330
const test = (userConfig as any).test || {};
330331

331-
// to simplify the processing of the config, we normalize the setupFiles to an array
332-
const userSetupFiles: string[] =
333-
typeof test.setupFiles === 'string' ? [test.setupFiles] : test.setupFiles || [];
334-
335332
if (userConfig.mode === 'test') {
333+
// to simplify the processing of the config, we normalize the setupFiles to an array
334+
const userSetupFiles: string[] =
335+
typeof test.setupFiles === 'string' ? [test.setupFiles] : test.setupFiles || [];
336+
336337
if (!test.environment && !options.ssr) {
337338
test.environment = 'jsdom';
338339
}
339340

340-
const jestDomImport = getJestDomExport(userSetupFiles);
341+
test.server = test.server || {};
342+
test.server.deps = test.server.deps || {};
343+
if (!test.server.deps.inline?.find((item: string | RegExp) => /solid-js/.test(item.toString()))) {
344+
test.server.deps.inline = [...(test.server.deps.inline || []), /solid-js/];
345+
}
341346

347+
const jestDomImport = getJestDomExport(userSetupFiles);
342348
if (jestDomImport) {
343-
test.setupFiles = [...userSetupFiles, require.resolve(jestDomImport)];
349+
test.setupFiles = [...userSetupFiles, jestDomImport];
344350
}
345351
}
346352

@@ -364,7 +370,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
364370
exclude: solidPkgsConfig.optimizeDeps.exclude,
365371
},
366372
ssr: solidPkgsConfig.ssr,
367-
...(test ? { test } : {}),
373+
...(test.server ? { test } : {}),
368374
};
369375
},
370376

0 commit comments

Comments
 (0)