forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete --target wc & multi-wc + tests
- Loading branch information
Showing
19 changed files
with
327 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<h1>{{ msg }}</h1> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data: () => ({ msg: 'hi' }) | ||
} | ||
</script> | ||
|
||
<style> | ||
h1 { color: red } | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
jest.setTimeout(20000) | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const portfinder = require('portfinder') | ||
const { createServer } = require('http-server') | ||
const mkdirp = require('mkdirp') | ||
const execa = require('execa') | ||
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer') | ||
|
||
const cwd = path.resolve(__dirname, 'temp') | ||
const binPath = require.resolve('@vue/cli/bin/vue') | ||
const write = (file, content) => fs.writeFileSync(path.join(cwd, file), content) | ||
|
||
const entryVue = fs.readFileSync(path.resolve(__dirname, 'entry.vue'), 'utf-8') | ||
|
||
beforeAll(() => { | ||
mkdirp.sync(cwd) | ||
write('testLib.vue', entryVue) | ||
}) | ||
|
||
let server, browser, page | ||
test('global build --target lib', async () => { | ||
const { stdout } = await execa(binPath, ['build', 'testLib.vue', '--target', 'lib'], { cwd }) | ||
|
||
expect(stdout).toMatch('Build complete.') | ||
|
||
const distDir = path.join(cwd, 'dist') | ||
const hasFile = file => fs.existsSync(path.join(distDir, file)) | ||
expect(hasFile('demo.html')).toBe(true) | ||
expect(hasFile('testLib.common.js')).toBe(true) | ||
expect(hasFile('testLib.umd.js')).toBe(true) | ||
expect(hasFile('testLib.umd.min.js')).toBe(true) | ||
expect(hasFile('testLib.css')).toBe(true) | ||
|
||
const port = await portfinder.getPortPromise() | ||
server = createServer({ root: distDir }) | ||
|
||
await new Promise((resolve, reject) => { | ||
server.listen(port, err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const launched = await launchPuppeteer(`http://localhost:${port}/demo.html`) | ||
browser = launched.browser | ||
page = launched.page | ||
|
||
const h1Text = await page.evaluate(() => { | ||
return document.querySelector('h1').textContent | ||
}) | ||
|
||
expect(h1Text).toMatch('hi') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
server.close() | ||
}) |
58 changes: 58 additions & 0 deletions
58
packages/@vue/cli-service-global/__tests__/globalServiceBuildWc.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
jest.setTimeout(20000) | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const portfinder = require('portfinder') | ||
const { createServer } = require('http-server') | ||
const mkdirp = require('mkdirp') | ||
const execa = require('execa') | ||
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer') | ||
|
||
const cwd = path.resolve(__dirname, 'temp') | ||
const binPath = require.resolve('@vue/cli/bin/vue') | ||
const write = (file, content) => fs.writeFileSync(path.join(cwd, file), content) | ||
|
||
const entryVue = fs.readFileSync(path.resolve(__dirname, 'entry.vue'), 'utf-8') | ||
|
||
beforeAll(() => { | ||
mkdirp.sync(cwd) | ||
write('my-wc.vue', entryVue) | ||
}) | ||
|
||
let server, browser, page | ||
test('global build --target wc', async () => { | ||
const { stdout } = await execa(binPath, ['build', 'my-wc.vue', '--target', 'wc'], { cwd }) | ||
|
||
expect(stdout).toMatch('Build complete.') | ||
|
||
const distDir = path.join(cwd, 'dist') | ||
const hasFile = file => fs.existsSync(path.join(distDir, file)) | ||
expect(hasFile('demo.html')).toBe(true) | ||
expect(hasFile('my-wc.js')).toBe(true) | ||
expect(hasFile('my-wc.min.js')).toBe(true) | ||
|
||
const port = await portfinder.getPortPromise() | ||
server = createServer({ root: distDir }) | ||
|
||
await new Promise((resolve, reject) => { | ||
server.listen(port, err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const launched = await launchPuppeteer(`http://localhost:${port}/demo.html`) | ||
browser = launched.browser | ||
page = launched.page | ||
|
||
const h1Text = await page.evaluate(() => { | ||
return document.querySelector('my-wc')._shadowRoot.querySelector('h1').textContent | ||
}) | ||
|
||
expect(h1Text).toMatch('hi') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
server.close() | ||
}) |
Empty file removed
0
packages/@vue/cli-service-global/__tests__/globalServiceBuildWebComponent.spec.js
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
jest.setTimeout(30000) | ||
|
||
const path = require('path') | ||
const portfinder = require('portfinder') | ||
const { createServer } = require('http-server') | ||
const { defaultPreset } = require('@vue/cli/lib/options') | ||
const create = require('@vue/cli-test-utils/createTestProject') | ||
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer') | ||
|
||
let server, browser, page | ||
test('build as single wc', async () => { | ||
const project = await create('build-multi-wc', defaultPreset) | ||
|
||
const { stdout } = await project.run(`vue-cli-service build --target multi-wc **/*.vue`) | ||
expect(stdout).toMatch('Build complete.') | ||
|
||
expect(project.has('dist/demo.html')).toBe(true) | ||
expect(project.has('dist/build-multi-wc.js')).toBe(true) | ||
expect(project.has('dist/build-multi-wc.min.js')).toBe(true) | ||
|
||
const port = await portfinder.getPortPromise() | ||
server = createServer({ root: path.join(project.dir, 'dist') }) | ||
|
||
await new Promise((resolve, reject) => { | ||
server.listen(port, err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const launched = await launchPuppeteer(`http://localhost:${port}/demo.html`) | ||
browser = launched.browser | ||
page = launched.page | ||
|
||
const styleCount = await page.evaluate(() => { | ||
return document.querySelector('build-multi-wc-app')._shadowRoot.querySelectorAll('style').length | ||
}) | ||
expect(styleCount).toBe(2) // should contain styles from both app and child | ||
|
||
const h1Text = await page.evaluate(() => { | ||
return document.querySelector('build-multi-wc-app')._shadowRoot.querySelector('h1').textContent | ||
}) | ||
expect(h1Text).toMatch('Welcome to Your Vue.js App') | ||
|
||
const childStyleCount = await page.evaluate(() => { | ||
return document.querySelector('build-multi-wc-hello-world')._shadowRoot.querySelectorAll('style').length | ||
}) | ||
expect(childStyleCount).toBe(1) | ||
|
||
const h2Text = await page.evaluate(() => { | ||
return document.querySelector('build-multi-wc-hello-world')._shadowRoot.querySelector('h2').textContent | ||
}) | ||
expect(h2Text).toMatch('Essential Links') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
server.close() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
jest.setTimeout(30000) | ||
|
||
const path = require('path') | ||
const portfinder = require('portfinder') | ||
const { createServer } = require('http-server') | ||
const { defaultPreset } = require('@vue/cli/lib/options') | ||
const create = require('@vue/cli-test-utils/createTestProject') | ||
const launchPuppeteer = require('@vue/cli-test-utils/launchPuppeteer') | ||
|
||
let server, browser, page | ||
test('build as single wc', async () => { | ||
const project = await create('build-wc', defaultPreset) | ||
|
||
const { stdout } = await project.run('vue-cli-service build --target wc src/components/HelloWorld.vue') | ||
expect(stdout).toMatch('Build complete.') | ||
|
||
expect(project.has('dist/demo.html')).toBe(true) | ||
expect(project.has('dist/build-wc.js')).toBe(true) | ||
expect(project.has('dist/build-wc.min.js')).toBe(true) | ||
|
||
const port = await portfinder.getPortPromise() | ||
server = createServer({ root: path.join(project.dir, 'dist') }) | ||
|
||
await new Promise((resolve, reject) => { | ||
server.listen(port, err => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
|
||
const launched = await launchPuppeteer(`http://localhost:${port}/demo.html`) | ||
browser = launched.browser | ||
page = launched.page | ||
|
||
const styleCount = await page.evaluate(() => { | ||
return document.querySelector('build-wc')._shadowRoot.querySelectorAll('style').length | ||
}) | ||
expect(styleCount).toBe(1) | ||
|
||
await page.evaluate(() => { | ||
document.querySelector('build-wc').msg = 'hello' | ||
}) | ||
const h1Text = await page.evaluate(() => { | ||
return document.querySelector('build-wc')._shadowRoot.querySelector('h1').textContent | ||
}) | ||
expect(h1Text).toBe('hello') | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
server.close() | ||
}) |
Empty file.
6 changes: 6 additions & 0 deletions
6
packages/@vue/cli-service/lib/commands/build/demo-multi-wc.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<title><%- htmlWebpackPlugin.options.libName %> demo</title> | ||
<script src="https://unpkg.com/vue"></script> | ||
<script src="./<%- htmlWebpackPlugin.options.libName %>.js"></script> | ||
<% for (const comp of htmlWebpackPlugin.options.components) { %> | ||
<<%= comp %>></<%= comp %>> | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.