(
test_dir: string,
config: ReturnType<typeof import('./assert').test>,
hydrate: boolean
)
| 61 | ); |
| 62 | |
| 63 | async function run_test( |
| 64 | test_dir: string, |
| 65 | config: ReturnType<typeof import('./assert').test>, |
| 66 | hydrate: boolean |
| 67 | ) { |
| 68 | const warnings: any[] = []; |
| 69 | |
| 70 | const build_result = await build({ |
| 71 | entryPoints: [`${__dirname}/driver.js`], |
| 72 | write: false, |
| 73 | define: { |
| 74 | __HYDRATE__: String(hydrate), |
| 75 | __CE_TEST__: String(test_dir.includes('custom-elements-samples')) |
| 76 | }, |
| 77 | alias: { |
| 78 | __MAIN_DOT_SVELTE__: path.resolve(test_dir, 'main.svelte'), |
| 79 | __CONFIG__: path.resolve(test_dir, '_config.js'), |
| 80 | 'assert.js': assert_file |
| 81 | }, |
| 82 | conditions: ['browser', 'production'], |
| 83 | plugins: [ |
| 84 | { |
| 85 | name: 'testing-runtime-browser', |
| 86 | setup(build) { |
| 87 | build.onLoad({ filter: /\.svelte$/ }, (args) => { |
| 88 | const compiled = compile(fs.readFileSync(args.path, 'utf-8').replace(/\r/g, ''), { |
| 89 | generate: 'client', |
| 90 | fragments, |
| 91 | ...config.compileOptions, |
| 92 | immutable: config.immutable, |
| 93 | customElement: test_dir.includes('custom-elements-samples'), |
| 94 | accessors: 'accessors' in config ? config.accessors : true |
| 95 | }); |
| 96 | |
| 97 | write(`${test_dir}/_output/client/${path.basename(args.path)}.js`, compiled.js.code); |
| 98 | |
| 99 | compiled.warnings.forEach((warning) => { |
| 100 | if (warning.code === 'options_deprecated_accessors') return; |
| 101 | warnings.push(warning); |
| 102 | }); |
| 103 | |
| 104 | if (compiled.css !== null) { |
| 105 | compiled.js.code += `document.head.innerHTML += \`<style>${compiled.css.code}</style>\``; |
| 106 | write( |
| 107 | `${test_dir}/_output/client/${path.basename(args.path)}.css`, |
| 108 | compiled.css.code |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | return { |
| 113 | contents: compiled.js.code, |
| 114 | loader: 'js' |
| 115 | }; |
| 116 | }); |
| 117 | } |
| 118 | } |
| 119 | ], |
| 120 | bundle: true, |
no test coverage detected