import fs from 'fs'; import { preprocess } from 'svelte/compiler'; import svelteDeepWind from './index.js'; test('Preprocessor respects ! on rtl classes', async () => { const inputFile = fs.readFileSync('./input/ImportantRTL.svelte', 'utf-8'); const result = await preprocess(inputFile, [svelteDeepWind({ rtl: true })]); fs.writeFileSync('./output/ImportantRTL.svelte', result.code, 'utf-8'); }); test('Preprocessor makes `global:` classes global', async () => { const result = await preprocess( `
`, [svelteDeepWind({ globalPrefix: true })] ); expect(result.code).toMatchInlineSnapshot( `"
"` ); }); test('Preprocessor allows rtl classes to be passed down to child component', async () => { const result = await preprocess( `
Hello
`, [svelteDeepWind({ rtl: true })] ); expect(result.code).toMatchInlineSnapshot(` "
Hello
" `); }); test('Preprocessor makes rtl and ltr classes global to keep Svelte compiler from stripping out', async () => { const result = await preprocess( `
LTR
LTR
RTL
`, [svelteDeepWind({ rtl: true })] ); expect(result.code).toMatchInlineSnapshot(` "
LTR
LTR
RTL
" `); }); test('Preprocessor handles line breaks @apply style lines', async () => { const result = await preprocess( ``, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` "" `); }); test('Preprocessor handles ! in Component class names by escaping it in deep name', async () => { const result = await preprocess( ` `, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` " " `); }); test('Preprocessor handles @apply and colons in style tag', async () => { const result = await preprocess( ` `, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` " " `); }); test('Preprocessor handles existing style tag', async () => { const inputFile = fs.readFileSync('./input/ButtonParent.svelte', 'utf-8'); const result = await preprocess(inputFile, [svelteDeepWind()]); expect(result.code).toMatchInlineSnapshot(` " " `); }); test('Preprocessor handles no style tag', async () => { const result = await preprocess( ` `, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` " " `); }); test('Preprocessor handles no component classes', async () => { const result = await preprocess( `
Decoy
`, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` "
Decoy
" `); }); test('Preprocessor skips a file if has Typescript and is not starting with script block', async () => { const result = await preprocess( ` `, [svelteDeepWind()] ); expect(result.code).toMatchInlineSnapshot(` " " `); }); test('Preprocessor handles file with Typescript', async () => { const inputFile = fs.readFileSync('./input/HasTypescript.svelte', 'utf-8'); const result = await preprocess(inputFile, [svelteDeepWind()]); fs.writeFileSync('./output/HasTypescript.svelte', result.code, 'utf-8'); }); test('Preprocessor handles file with Typescript and @apply classes in style block', async () => { const inputFile = fs.readFileSync('./input/__layout.svelte', 'utf-8'); const result = await preprocess(inputFile, [svelteDeepWind()]); expect(result.code).toEqual(inputFile); });