Skip to content

Commit

Permalink
chore: fix test run when linking vite (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Oct 23, 2023
1 parent a030782 commit efd571f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
14 changes: 11 additions & 3 deletions packages/vite-plugin-svelte/__tests__/preprocess.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ const fixtureDir = normalizePath(
path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixtures', 'preprocess')
);

/** @type {import('vite').InlineConfig} */
const inlineConfig = {
configFile: false,
root: fixtureDir
};

describe('vitePreprocess', () => {
it('returns function', () => {
const preprocessorGroup = vitePreprocess({ script: true, style: true });
const preprocessorGroup = vitePreprocess({ script: true, style: inlineConfig });
expect(typeof preprocessorGroup).toBe('object');
expect(typeof preprocessorGroup.script).toBe('function');
expect(typeof preprocessorGroup.style).toBe('function');
});

describe('style', async () => {
it('preprocess with postcss if no lang', async () => {
const preprocessorGroup = vitePreprocess({ style: {} });
const preprocessorGroup = vitePreprocess({ style: inlineConfig });
const style = /**@type {import('svelte/types/compiler/preprocess').Preprocessor} */ (
preprocessorGroup.style
);
Expand All @@ -37,7 +43,9 @@ describe('vitePreprocess', () => {
});

it('produces sourcemap with relative filename', async () => {
const preprocessorGroup = vitePreprocess({ style: { css: { devSourcemap: true } } });
const preprocessorGroup = vitePreprocess({
style: { ...inlineConfig, css: { devSourcemap: true } }
});
const style = /**@type {import('svelte/types/compiler/preprocess').Preprocessor} */ (
preprocessorGroup.style
);
Expand Down
1 change: 1 addition & 0 deletions packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"devDependencies": {
"@types/debug": "^4.1.10",
"esbuild": "^0.19.5",
"sass": "^1.69.4",
"svelte": "^4.2.2",
"vite": "^5.0.0-beta.11"
}
Expand Down
15 changes: 7 additions & 8 deletions packages/vite-plugin-svelte/src/utils/load-svelte-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ export const knownSvelteConfigNames = [
'svelte.config.mjs'
];

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

/** @type {import('../index.d.ts').loadSvelteConfig} */
export async function loadSvelteConfig(viteConfig, inlineOptions) {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efd571f

Please sign in to comment.