Skip to content

Commit 3c669e8

Browse files
committed
test: add test for styles
1 parent 2c5d9a1 commit 3c669e8

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@
5555
"lint-staged": "^10.3.0",
5656
"memfs": "^3.1.2",
5757
"mini-css-extract-plugin": "^0.11.2",
58+
"normalize-newline": "^3.0.0",
5859
"prettier": "^2.1.1",
5960
"pug": "^2.0.0",
6061
"pug-plain-loader": "^1.0.0",
62+
"style-loader": "^1.2.1",
6163
"stylus": "^0.54.7",
6264
"stylus-loader": "^3.0.2",
6365
"ts-jest": "^26.2.0",

Diff for: test/core.spec.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { mockBundleAndRun } from './utils'
1+
import { mockBundleAndRun, normalizeNewline } from './utils'
22

33
test('basic', async () => {
4-
const { instance } = await mockBundleAndRun({ entry: 'basic.vue' })
4+
const { window, instance } = await mockBundleAndRun({ entry: 'basic.vue' })
55

66
// <h2 class="red">{{msg}}</h2>
77
expect(instance.$el.tagName).toBe('H2')
88
expect(instance.$el.className).toBe('red')
99
expect(instance.$el.textContent).toBe('Hello from Component A!')
10+
11+
const style = normalizeNewline(
12+
window.document.querySelector('style')!.textContent!
13+
)
14+
expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
1015
})
1116

1217
test('script setup', async () => {

Diff for: test/utils.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import path from 'path'
33
import webpack from 'webpack'
44
import merge from 'webpack-merge'
5-
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
5+
// import MiniCssExtractPlugin from 'mini-css-extract-plugin'
66
import { fs as mfs } from 'memfs'
77

88
import { JSDOM, VirtualConsole } from 'jsdom'
@@ -37,10 +37,11 @@ const baseConfig: webpack.Configuration = {
3737
{
3838
test: /\.css$/,
3939
use: [
40-
{
41-
loader: MiniCssExtractPlugin.loader,
42-
options: { hmr: true },
43-
},
40+
// {
41+
// loader: MiniCssExtractPlugin.loader,
42+
// options: { hmr: true },
43+
// },
44+
'style-loader',
4445
'css-loader',
4546
],
4647
},
@@ -52,9 +53,9 @@ const baseConfig: webpack.Configuration = {
5253
__VUE_OPTIONS_API__: true,
5354
__VUE_PROD_DEVTOOLS__: false,
5455
}),
55-
new MiniCssExtractPlugin({
56-
filename: '[name].css',
57-
}),
56+
// new MiniCssExtractPlugin({
57+
// filename: '[name].css',
58+
// }),
5859
],
5960
}
6061

@@ -142,7 +143,7 @@ export async function mockBundleAndRun(
142143

143144
let jsdomError
144145
const dom = new JSDOM(
145-
`<!DOCTYPE html><html><head></head><body></body></html>`,
146+
`<!DOCTYPE html><html><head></head><body><div id="#app"></div></body></html>`,
146147
{
147148
runScripts: 'outside-only',
148149
virtualConsole: new VirtualConsole(),
@@ -171,3 +172,7 @@ export async function mockBundleAndRun(
171172
jsdomError,
172173
}
173174
}
175+
176+
export function normalizeNewline(input: string): string {
177+
return input.replace(new RegExp('\r\n', 'g'), '\n')
178+
}

Diff for: tsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
"strictNullChecks": true,
1515
"noImplicitAny": true,
1616
"removeComments": false,
17-
"skipLibCheck": true,
1817
"lib": [
1918
"es6",
20-
"es7"
19+
"es7",
20+
"DOM"
2121
]
2222
},
2323
"include": [
24-
"src"
24+
"src",
25+
"test"
2526
]
2627
}

Diff for: yarn.lock

+14-1
Original file line numberDiff line numberDiff line change
@@ -5648,6 +5648,11 @@ node-releases@^1.1.61:
56485648
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.61.tgz#707b0fca9ce4e11783612ba4a2fcba09047af16e"
56495649
integrity sha512-DD5vebQLg8jLCOzwupn954fbIiZht05DAZs0k2u8NStSe6h9XdsuIQL8hSRKYiU8WUQRznmSDrKGbv3ObOmC7g==
56505650

5651+
normalize-newline@^3.0.0:
5652+
version "3.0.0"
5653+
resolved "https://registry.yarnpkg.com/normalize-newline/-/normalize-newline-3.0.0.tgz#1cbea804aba436001f83938ab21ec039d69ae9d3"
5654+
integrity sha1-HL6oBKukNgAfg5OKsh7AOdaa6dM=
5655+
56515656
normalize-package-data@^2.5.0:
56525657
version "2.5.0"
56535658
resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8"
@@ -6846,7 +6851,7 @@ schema-utils@^1.0.0:
68466851
ajv-errors "^1.0.0"
68476852
ajv-keywords "^3.1.0"
68486853

6849-
schema-utils@^2.0.0, schema-utils@^2.6.5, schema-utils@^2.7.1:
6854+
schema-utils@^2.0.0, schema-utils@^2.6.5, schema-utils@^2.6.6, schema-utils@^2.7.1:
68506855
version "2.7.1"
68516856
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7"
68526857
integrity sha512-SHiNtMOUGWBQJwzISiVYKu82GiV4QYGePp3odlY1tuKO7gPtphAT5R/py0fA6xtbgLL/RvtJZnU9b8s0F1q0Xg==
@@ -7416,6 +7421,14 @@ strip-indent@^2.0.0:
74167421
resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-2.0.0.tgz#5ef8db295d01e6ed6cbf7aab96998d7822527b68"
74177422
integrity sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g=
74187423

7424+
style-loader@^1.2.1:
7425+
version "1.2.1"
7426+
resolved "https://registry.yarnpkg.com/style-loader/-/style-loader-1.2.1.tgz#c5cbbfbf1170d076cfdd86e0109c5bba114baa1a"
7427+
integrity sha512-ByHSTQvHLkWE9Ir5+lGbVOXhxX10fbprhLvdg96wedFZb4NDekDPxVKv5Fwmio+QcMlkkNfuK+5W1peQ5CUhZg==
7428+
dependencies:
7429+
loader-utils "^2.0.0"
7430+
schema-utils "^2.6.6"
7431+
74197432
stylus-loader@^3.0.2:
74207433
version "3.0.2"
74217434
resolved "https://registry.yarnpkg.com/stylus-loader/-/stylus-loader-3.0.2.tgz#27a706420b05a38e038e7cacb153578d450513c6"

0 commit comments

Comments
 (0)