Skip to content

Commit 0cac25c

Browse files
committed
add tests
1 parent 5372279 commit 0cac25c

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

packages/svelte/src/compiler/phases/3-transform/css/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export function render_stylesheet(source, analysis, options) {
5959
// generateMap takes care of calculating source relative to file
6060
source: options.filename,
6161
file: options.cssOutputFilename || options.filename
62-
})
62+
}),
63+
hasGlobal: analysis.css.has_unscoped_global
6364
};
6465

6566
merge_with_preprocessor_map(css, options, css.map.sources[0]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
hasGlobal: true
5+
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { test } from '../../test';
22

33
export default test({
4-
warnings: []
4+
warnings: [],
5+
6+
hasGlobal: false
57
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
hasGlobal: true
5+
});

packages/svelte/tests/css/test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface CssTest extends BaseTest {
3434
compileOptions?: Partial<CompileOptions>;
3535
warnings?: Warning[];
3636
props?: Record<string, any>;
37+
hasGlobal?: boolean;
3738
}
3839

3940
/**
@@ -78,6 +79,14 @@ const { test, run } = suite<CssTest>(async (config, cwd) => {
7879
// assert_html_equal(actual_ssr, expected.html);
7980
}
8081

82+
if (config.hasGlobal !== undefined) {
83+
const metadata = JSON.parse(
84+
fs.readFileSync(`${cwd}/_output/client/input.svelte.css.json`, 'utf-8')
85+
);
86+
87+
assert.equal(metadata.hasGlobal, config.hasGlobal);
88+
}
89+
8190
const dom_css = fs.readFileSync(`${cwd}/_output/client/input.svelte.css`, 'utf-8').trim();
8291
const ssr_css = fs.readFileSync(`${cwd}/_output/server/input.svelte.css`, 'utf-8').trim();
8392

packages/svelte/tests/helpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export async function compile_directory(
146146

147147
if (compiled.css) {
148148
write(`${output_dir}/${file}.css`, compiled.css.code);
149+
write(
150+
`${output_dir}/${file}.css.json`,
151+
JSON.stringify({ hasGlobal: compiled.css.hasGlobal })
152+
);
149153
if (output_map) {
150154
write(`${output_dir}/${file}.css.map`, JSON.stringify(compiled.css.map, null, '\t'));
151155
}

0 commit comments

Comments
 (0)