Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit dd6e1c1

Browse files
committed
test: add e2e test setup
1 parent 7b12f1b commit dd6e1c1

File tree

8 files changed

+335
-11
lines changed

8 files changed

+335
-11
lines changed

.github/workflows/ci.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,32 @@ jobs:
4040
with:
4141
name: coverage
4242
path: coverage/
43+
44+
e2e:
45+
name: E2E tests
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v2
49+
50+
- name: Setup node_modules cache
51+
uses: actions/cache@v1
52+
env:
53+
cache-name: yarn
54+
with:
55+
path: .yarn
56+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
57+
restore-keys: |
58+
${{ runner.os }}-build-${{ env.cache-name }}-
59+
${{ runner.os }}-build-
60+
61+
- name: Install yarn
62+
run: hash yarn 2>/dev/null || curl -s -L https://yarnpkg.com/install.sh | sudo node
63+
64+
- name: Install dependencies and build packages
65+
run: |
66+
yarn config set cache-folder $(pwd)/.yarn
67+
yarn install --frozen-lockfile
68+
yarn run build
69+
70+
- name: Run unit tests
71+
run: yarn test:e2e

examples/css-modules/rollup.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import VuePlugin from 'rollup-plugin-vue'
2-
import postcss from 'rollup-plugin-postcss'
3-
import resolve from '@rollup/plugin-node-resolve'
2+
import PostCSS from 'rollup-plugin-postcss'
3+
import NodeResolve from '@rollup/plugin-node-resolve'
44

55
/** @type {import('rollup').RollupOptions[]} */
66
const config = [
@@ -12,15 +12,19 @@ const config = [
1212
sourcemap: 'inline',
1313
},
1414
plugins: [
15-
resolve(),
15+
// Resolve packages from `node_modules` e.g. `style-inject` module
16+
// used by `rollup-plugin-postcss` to inline CSS.
17+
NodeResolve(),
1618
VuePlugin(),
17-
postcss({
19+
// Process only `<style module>` blocks.
20+
PostCSS({
1821
modules: {
1922
generateScopedName: '[local]___[hash:base64:5]',
2023
},
2124
include: /&module=.*\.css$/,
2225
}),
23-
postcss({ include: /(?<!&module=.*)\.css$/ }),
26+
// Process all `<style>` blocks except `<style module>`.
27+
PostCSS({ include: /(?<!&module=.*)\.css$/ }),
2428
],
2529
external(id) {
2630
return /^(vue)$/.test(id)

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
rootDir: __dirname,
55
testEnvironment: 'node',
66
transform: {
7-
'^.+\\.ts$': 'ts-jest',
7+
'^.+\\.(ts|js)$': 'ts-jest',
88
},
99
coveragePathIgnorePatterns: ['.*\\.spec\\.ts'],
1010
globals: {

jest.e2e.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const config = require('./jest.config')
2+
3+
module.exports = {
4+
...config,
5+
testMatch: ['**/*.e2e.ts'],
6+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"build": "tsc -p .",
1313
"prepublishOnly": "tsc -p .",
1414
"dev": "tsc -w -p .",
15-
"test:unit": "jest"
15+
"test": "run-p test:*",
16+
"test:unit": "jest",
17+
"test:e2e": "jest --config jest.e2e.config.js"
1618
},
1719
"dependencies": {
1820
"debug": "^4.1.1",
@@ -30,6 +32,7 @@
3032
"husky": "^4.2.0",
3133
"jest": "^26.0.1",
3234
"lint-staged": "^10.1.7",
35+
"npm-run-all": "^4.1.5",
3336
"prettier": "^2.0.5",
3437
"rollup": "^2.7.2",
3538
"ts-jest": "^26.0.0",

test/core.e2e.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { rollup, RollupOutput, RollupWarning } from 'rollup'
2+
3+
describe('simple', () => {
4+
let result!: RollupOutput
5+
6+
beforeAll(async () => {
7+
result = await roll('simple')
8+
})
9+
10+
it('should compile <template>', () => {
11+
expect(result.output[0].code).toEqual(expect.stringContaining('.render ='))
12+
})
13+
})
14+
15+
describe('css-modules', () => {
16+
let result!: RollupOutput
17+
18+
beforeAll(async () => {
19+
result = await roll('css-modules')
20+
})
21+
22+
it('should process <style module> blocks', () => {
23+
expect(result.output[0].code).toEqual(
24+
expect.stringContaining('cssModules["$style"] =')
25+
)
26+
expect(result.output[0].code).not.toEqual(
27+
expect.stringContaining('.red {\n color: red;\n}')
28+
)
29+
expect(result.output[0].code).toEqual(expect.stringContaining('._red_'))
30+
expect(result.output[0].code).toEqual(
31+
expect.stringContaining('{"red":"_red_')
32+
)
33+
})
34+
35+
it('should process <style scoped> blocks', () => {
36+
expect(result.output[0].code).toEqual(
37+
expect.stringContaining('.__scopeId = "data-v-')
38+
)
39+
expect(result.output[0].code).not.toEqual(
40+
expect.stringContaining('.green {\n color: red;\n}')
41+
)
42+
expect(result.output[0].code).toEqual(
43+
expect.stringContaining('.green[data-v-')
44+
)
45+
})
46+
})
47+
48+
import Path from 'path'
49+
async function roll(name: string) {
50+
const configFile = `../examples/${name}/rollup.config.js`
51+
const configModule = require(configFile)
52+
const configs = configModule.__esModule ? configModule.default : configModule
53+
const config = Array.isArray(configs) ? configs[0] : configs
54+
55+
config.input = Path.resolve(__dirname, Path.dirname(configFile), config.input)
56+
delete config.output
57+
58+
config.onwarn = function (warning: RollupWarning, warn: Function) {
59+
switch (warning.code) {
60+
case 'UNUSED_EXTERNAL_IMPORT':
61+
return
62+
default:
63+
warning.message = `(${name}) ${warning.message}`
64+
warn(warning)
65+
}
66+
}
67+
68+
const bundle = await rollup(config)
69+
70+
return bundle.generate({ format: 'esm' })
71+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src", "types"],
2+
"include": ["src", "types", "test"],
33
"exclude": ["**/*.spec.ts"],
44
"compilerOptions": {
55
"target": "esnext",
@@ -11,6 +11,7 @@
1111
"rootDir": "src",
1212
"outDir": "dist",
1313
"strict": true,
14+
"allowJs": true,
1415
"noImplicitAny": true,
1516
"strictNullChecks": true,
1617
"strictFunctionTypes": true,

0 commit comments

Comments
 (0)