-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
ssr.noExternal
even if not present in project packag…
…e.json
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { beforeEach, describe, expect, test, vi } from 'vitest' | ||
|
||
import { svelteTesting } from '../vite.js' | ||
import { IS_JEST } from './utils.js' | ||
|
||
describe.skipIf(IS_JEST)('vite plugin', () => { | ||
beforeEach(() => { | ||
vi.stubEnv('VITEST', '1') | ||
}) | ||
|
||
test('does not modify config if disabled', () => { | ||
const subject = svelteTesting({ | ||
resolveBrowser: false, | ||
autoCleanup: false, | ||
noExternal: false, | ||
}) | ||
|
||
const config = {} | ||
subject.config(config) | ||
|
||
expect(config).toEqual({}) | ||
}) | ||
|
||
test('does not modify config if not Vitest', () => { | ||
vi.stubEnv('VITEST', '') | ||
|
||
const subject = svelteTesting() | ||
const config = {} | ||
|
||
subject.config(config) | ||
|
||
expect(config).toEqual({}) | ||
}) | ||
|
||
test.each([ | ||
{ | ||
config: { resolve: { conditions: ['node'] } }, | ||
expectedConditions: ['browser', 'node'], | ||
}, | ||
{ | ||
config: { resolve: { conditions: ['svelte', 'node'] } }, | ||
expectedConditions: ['svelte', 'browser', 'node'], | ||
}, | ||
])( | ||
'adds browser condition if necessary', | ||
({ config, expectedConditions }) => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone(config) | ||
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
Check failure on line 48 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds browser condition if necessary
|
||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
resolve: { | ||
conditions: expectedConditions, | ||
}, | ||
}) | ||
} | ||
) | ||
|
||
test.each([ | ||
{ | ||
config: {}, | ||
expectedConditions: [], | ||
}, | ||
{ | ||
config: { resolve: { conditions: [] } }, | ||
expectedConditions: [], | ||
}, | ||
{ | ||
config: { resolve: { conditions: ['svelte'] } }, | ||
expectedConditions: ['svelte'], | ||
}, | ||
])( | ||
'skips browser condition if possible', | ||
({ config, expectedConditions }) => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone(config) | ||
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
Check failure on line 77 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > skips browser condition if possible
|
||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
resolve: { | ||
conditions: expectedConditions, | ||
}, | ||
}) | ||
} | ||
) | ||
|
||
test.each([ | ||
{ | ||
config: {}, | ||
expectedSetupFiles: [expect.stringMatching(/src\/vitest.js$/u)], | ||
}, | ||
{ | ||
config: { test: { setupFiles: [] } }, | ||
expectedSetupFiles: [expect.stringMatching(/src\/vitest.js$/u)], | ||
}, | ||
{ | ||
config: { test: { setupFiles: 'other-file.js' } }, | ||
expectedSetupFiles: [ | ||
'other-file.js', | ||
expect.stringMatching(/src\/vitest.js$/u), | ||
], | ||
}, | ||
])('adds cleanup', ({ config, expectedSetupFiles }) => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone(config) | ||
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
Check failure on line 107 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds cleanup
|
||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
test: { | ||
setupFiles: expectedSetupFiles, | ||
}, | ||
}) | ||
}) | ||
|
||
test.each([ | ||
{ | ||
config: { ssr: { noExternal: [] } }, | ||
expectedNoExternal: ['@testing-library/svelte'], | ||
}, | ||
{ | ||
config: {}, | ||
expectedNoExternal: ['@testing-library/svelte'], | ||
}, | ||
{ | ||
config: { ssr: { noExternal: 'other-file.js' } }, | ||
expectedNoExternal: ['other-file.js', '@testing-library/svelte'], | ||
}, | ||
{ | ||
config: { ssr: { noExternal: /other/u } }, | ||
expectedNoExternal: [/other/u, '@testing-library/svelte'], | ||
}, | ||
])('adds noExternal rule', ({ config, expectedNoExternal }) => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone(config) | ||
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 3, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:jsdomsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
Check failure on line 137 in src/__tests__/vite-plugin.test.js GitHub Actions / Node 16, Svelte 4, test:vitest:happy-domsrc/__tests__/vite-plugin.test.js > vite plugin > adds noExternal rule
|
||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
ssr: { | ||
noExternal: expectedNoExternal, | ||
}, | ||
}) | ||
}) | ||
|
||
test.each([ | ||
{ | ||
config: { ssr: { noExternal: true } }, | ||
expectedNoExternal: true, | ||
}, | ||
{ | ||
config: { ssr: { noExternal: '@testing-library/svelte' } }, | ||
expectedNoExternal: '@testing-library/svelte', | ||
}, | ||
{ | ||
config: { ssr: { noExternal: /svelte/u } }, | ||
expectedNoExternal: /svelte/u, | ||
}, | ||
])('skips noExternal if able', ({ config, expectedNoExternal }) => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone(config) | ||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
ssr: { | ||
noExternal: expectedNoExternal, | ||
}, | ||
}) | ||
}) | ||
|
||
test('bails on noExternal if input is unexpected', () => { | ||
const subject = svelteTesting() | ||
const viteConfig = structuredClone({ ssr: { noExternal: false } }) | ||
|
||
subject.config(viteConfig) | ||
|
||
expect(viteConfig).toMatchObject({ | ||
ssr: { | ||
noExternal: false, | ||
}, | ||
}) | ||
}) | ||
}) |