diff --git a/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts b/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts index 95fe97a1b953ba..789adba23ae021 100644 --- a/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts +++ b/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts @@ -1,8 +1,23 @@ import { findAssetFile, getColor, isBuild, readManifest } from '../../testUtils' -test('should load both stylesheets', async () => { +test('should load all stylesheets', async () => { expect(await getColor('h1')).toBe('red') expect(await getColor('h2')).toBe('blue') + expect(await getColor('.dynamic')).toBe('green') +}) + +test('should load dynamic import with inline', async () => { + const css = await page.textContent('.dynamic-inline') + expect(css).toMatch('.inline') + + expect(await getColor('.inline')).not.toBe('yellow') +}) + +test('should load dynamic import with module', async () => { + const css = await page.textContent('.dynamic-module') + expect(css).toMatch('_mod_') + + expect(await getColor('.mod')).toBe('yellow') }) if (isBuild) { @@ -10,6 +25,7 @@ if (isBuild) { expect(findAssetFile(/style.*\.js$/)).toBe('') expect(findAssetFile('main.*.js$')).toMatch(`/* empty css`) expect(findAssetFile('other.*.js$')).toMatch(`/* empty css`) + expect(findAssetFile(/async.*\.js$/)).toBe('') }) test('should generate correct manifest', async () => { diff --git a/packages/playground/css-codesplit/async.css b/packages/playground/css-codesplit/async.css new file mode 100644 index 00000000000000..4902b2e7bee811 --- /dev/null +++ b/packages/playground/css-codesplit/async.css @@ -0,0 +1,3 @@ +.dynamic { + color: green; +} diff --git a/packages/playground/css-codesplit/index.html b/packages/playground/css-codesplit/index.html index 6b7b3bb2b4dc2d..63bdb59e11dc6b 100644 --- a/packages/playground/css-codesplit/index.html +++ b/packages/playground/css-codesplit/index.html @@ -1,2 +1,11 @@ +
This should be green
+This should not be yellow
+ +This should be yellow
+ + diff --git a/packages/playground/css-codesplit/inline.css b/packages/playground/css-codesplit/inline.css new file mode 100644 index 00000000000000..b2a2b5f1ead51f --- /dev/null +++ b/packages/playground/css-codesplit/inline.css @@ -0,0 +1,3 @@ +.inline { + color: yellow; +} diff --git a/packages/playground/css-codesplit/main.js b/packages/playground/css-codesplit/main.js index 8c80df2c181511..eb6e703f79e718 100644 --- a/packages/playground/css-codesplit/main.js +++ b/packages/playground/css-codesplit/main.js @@ -1,6 +1,15 @@ import './style.css' import './main.css' -document.getElementById( - 'app' -).innerHTML = `