From e978512048ee25511ad8717c42081fd6cebeab5a Mon Sep 17 00:00:00 2001
From: CHOYSEN
Date: Fri, 8 Oct 2021 19:14:27 +0800
Subject: [PATCH] test: for special query
---
packages/playground/css/__tests__/css.spec.ts | 21 ++++++++++++++-----
packages/playground/css/index.html | 10 +++++++--
packages/playground/css/inlined.css | 3 ---
packages/playground/css/main.js | 14 ++++++++++---
packages/playground/css/special-query.scss | 13 ++++++++++++
5 files changed, 48 insertions(+), 13 deletions(-)
delete mode 100644 packages/playground/css/inlined.css
create mode 100644 packages/playground/css/special-query.scss
diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts
index ad5d9f344813e4..c62c2d5f46ae84 100644
--- a/packages/playground/css/__tests__/css.spec.ts
+++ b/packages/playground/css/__tests__/css.spec.ts
@@ -1,5 +1,3 @@
-import fs from 'fs'
-import path from 'path'
import {
editFile,
findAssetFile,
@@ -7,7 +5,7 @@ import {
getColor,
isBuild,
removeFile,
- testDir,
+ readFile,
untilUpdated
} from '../../testUtils'
@@ -334,7 +332,20 @@ test('Url separation', async () => {
}
})
-test('inlined', async () => {
+test('special query', async () => {
// should not insert css
- expect(await getColor('.inlined')).toBe('black')
+ expect(await getColor('.url')).toBe('black')
+ expect(await getColor('.raw')).toBe('black')
+ expect(await getColor('.inline')).toBe('black')
+
+ const source = readFile('special-query.scss')
+
+ expect(await page.textContent('.url')).toMatch(
+ isBuild
+ ? `data:application/javascript;base64,${Buffer.from(source).toString(
+ 'base64'
+ )}`
+ : '/special-query.scss'
+ )
+ expect(await page.textContent('.raw')).toMatch(source)
})
diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html
index 7a79bb1629f989..eb7190fa7cef37 100644
--- a/packages/playground/css/index.html
+++ b/packages/playground/css/index.html
@@ -102,8 +102,14 @@ CSS
Url separation preservation: should have valid background-image
- Inlined import - this should NOT be red.
-
+ ?url import - this should NOT be green
+
+
+ ?raw import - this should NOT be green
+
+
+ ?inline import - this should NOT be green
+
diff --git a/packages/playground/css/inlined.css b/packages/playground/css/inlined.css
deleted file mode 100644
index 68217369431dbd..00000000000000
--- a/packages/playground/css/inlined.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.inlined {
- color: green;
-}
diff --git a/packages/playground/css/main.js b/packages/playground/css/main.js
index cd2d6fda9ac0d5..cfce69f832552e 100644
--- a/packages/playground/css/main.js
+++ b/packages/playground/css/main.js
@@ -63,6 +63,14 @@ if (import.meta.env.DEV) {
import('./async-treeshaken')
}
-// inlined
-import inlined from './inlined.css?inline'
-text('.inlined-code', inlined)
+// ?url import
+import url from './special-query.scss?url'
+text('.url-code', url)
+
+// ?raw import
+import raw from './special-query.scss?raw'
+text('.raw-code', raw)
+
+// ?inline import
+import inline from './special-query.scss?inline'
+text('.inline-code', inline)
diff --git a/packages/playground/css/special-query.scss b/packages/playground/css/special-query.scss
new file mode 100644
index 00000000000000..49611ccc920c7a
--- /dev/null
+++ b/packages/playground/css/special-query.scss
@@ -0,0 +1,13 @@
+.inline {
+ color: green;
+}
+
+.url {
+ color: green;
+}
+
+.raw {
+ & {
+ color: green;
+ }
+}