Skip to content

Commit efd571f

Browse files
authored
chore: fix test run when linking vite (#773)
1 parent a030782 commit efd571f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

packages/vite-plugin-svelte/__tests__/preprocess.spec.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ const fixtureDir = normalizePath(
88
path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixtures', 'preprocess')
99
);
1010

11+
/** @type {import('vite').InlineConfig} */
12+
const inlineConfig = {
13+
configFile: false,
14+
root: fixtureDir
15+
};
16+
1117
describe('vitePreprocess', () => {
1218
it('returns function', () => {
13-
const preprocessorGroup = vitePreprocess({ script: true, style: true });
19+
const preprocessorGroup = vitePreprocess({ script: true, style: inlineConfig });
1420
expect(typeof preprocessorGroup).toBe('object');
1521
expect(typeof preprocessorGroup.script).toBe('function');
1622
expect(typeof preprocessorGroup.style).toBe('function');
1723
});
1824

1925
describe('style', async () => {
2026
it('preprocess with postcss if no lang', async () => {
21-
const preprocessorGroup = vitePreprocess({ style: {} });
27+
const preprocessorGroup = vitePreprocess({ style: inlineConfig });
2228
const style = /**@type {import('svelte/types/compiler/preprocess').Preprocessor} */ (
2329
preprocessorGroup.style
2430
);
@@ -37,7 +43,9 @@ describe('vitePreprocess', () => {
3743
});
3844

3945
it('produces sourcemap with relative filename', async () => {
40-
const preprocessorGroup = vitePreprocess({ style: { css: { devSourcemap: true } } });
46+
const preprocessorGroup = vitePreprocess({
47+
style: { ...inlineConfig, css: { devSourcemap: true } }
48+
});
4149
const style = /**@type {import('svelte/types/compiler/preprocess').Preprocessor} */ (
4250
preprocessorGroup.style
4351
);

packages/vite-plugin-svelte/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"devDependencies": {
5454
"@types/debug": "^4.1.10",
5555
"esbuild": "^0.19.5",
56+
"sass": "^1.69.4",
5657
"svelte": "^4.2.2",
5758
"vite": "^5.0.0-beta.11"
5859
}

packages/vite-plugin-svelte/src/utils/load-svelte-config.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ export const knownSvelteConfigNames = [
1616
'svelte.config.mjs'
1717
];
1818

19-
// hide dynamic import from ts transform to prevent it turning into a require
20-
// see https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
21-
// also use timestamp query to avoid caching on reload
22-
const dynamicImportDefault = new Function(
23-
'path',
24-
'timestamp',
25-
'return import(path + "?t=" + timestamp).then(m => m.default)'
26-
);
19+
/**
20+
* @param {string} filePath
21+
* @param {number} timestamp
22+
*/
23+
async function dynamicImportDefault(filePath, timestamp) {
24+
return await import(filePath + '?t=' + timestamp).then((m) => m.default);
25+
}
2726

2827
/** @type {import('../index.d.ts').loadSvelteConfig} */
2928
export async function loadSvelteConfig(viteConfig, inlineOptions) {

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)