Skip to content

Commit

Permalink
test: skip build tests in test-sw
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 19, 2020
1 parent 6047305 commit 6bf80d7
Showing 1 changed file with 52 additions and 48 deletions.
100 changes: 52 additions & 48 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,61 +560,65 @@ describe('vite', () => {
}

// test build first since we are going to edit the fixtures when testing dev
describe('build', () => {
let staticServer
beforeAll(async () => {
console.log('building...')
const buildOutput = await execa(binPath, ['build'], {
cwd: tempDir
// no need to run build tests when testing service worker mode since it's
// dev only
if (!process.env.USE_SW) {
describe('build', () => {
let staticServer
beforeAll(async () => {
console.log('building...')
const buildOutput = await execa(binPath, ['build'], {
cwd: tempDir
})
expect(buildOutput.stdout).toMatch('Build completed')
expect(buildOutput.stderr).toBe('')
console.log('build complete. running build tests...')
})
expect(buildOutput.stdout).toMatch('Build completed')
expect(buildOutput.stderr).toBe('')
console.log('build complete. running build tests...')
})

afterAll(() => {
console.log('build test done.')
if (staticServer) staticServer.close()
})

describe('assertions', () => {
beforeAll(async () => {
// start a static file server
const app = new (require('koa'))()
app.use(require('koa-static')(path.join(tempDir, 'dist')))
staticServer = require('http').createServer(app.callback())
await new Promise((r) => staticServer.listen(3001, r))

page = await browser.newPage()
await page.goto('http://localhost:3001')
afterAll(() => {
console.log('build test done.')
if (staticServer) staticServer.close()
})

declareTests(true)
})
describe('assertions', () => {
beforeAll(async () => {
// start a static file server
const app = new (require('koa'))()
app.use(require('koa-static')(path.join(tempDir, 'dist')))
staticServer = require('http').createServer(app.callback())
await new Promise((r) => staticServer.listen(3001, r))

test('css codesplit in async chunks', async () => {
const colorToMatch = /#8B4513/i // from TestAsync.vue
page = await browser.newPage()
await page.goto('http://localhost:3001')
})

const files = await fs.readdir(path.join(tempDir, 'dist/_assets'))
const cssFile = files.find((f) => f.endsWith('.css'))
const css = await fs.readFile(
path.join(tempDir, 'dist/_assets', cssFile),
'utf-8'
)
// should be extracted from the main css file
expect(css).not.toMatch(colorToMatch)
// should be inside the split chunk file
const asyncChunk = files.find(
(f) => f.startsWith('TestAsync') && f.endsWith('.js')
)
const code = await fs.readFile(
path.join(tempDir, 'dist/_assets', asyncChunk),
'utf-8'
)
// should be inside the async chunk
expect(code).toMatch(colorToMatch)
declareTests(true)
})

test('css codesplit in async chunks', async () => {
const colorToMatch = /#8B4513/i // from TestAsync.vue

const files = await fs.readdir(path.join(tempDir, 'dist/_assets'))
const cssFile = files.find((f) => f.endsWith('.css'))
const css = await fs.readFile(
path.join(tempDir, 'dist/_assets', cssFile),
'utf-8'
)
// should be extracted from the main css file
expect(css).not.toMatch(colorToMatch)
// should be inside the split chunk file
const asyncChunk = files.find(
(f) => f.startsWith('TestAsync') && f.endsWith('.js')
)
const code = await fs.readFile(
path.join(tempDir, 'dist/_assets', asyncChunk),
'utf-8'
)
// should be inside the async chunk
expect(code).toMatch(colorToMatch)
})
})
})
}

describe('dev', () => {
beforeAll(async () => {
Expand Down

0 comments on commit 6bf80d7

Please sign in to comment.