mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
test: refactor cli integration tests (#6537)
This commit is contained in:
parent
a0ef4a3736
commit
67d5601142
@ -1,3 +1,8 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const corePackages = fs.readdirSync(path.resolve(__dirname, 'packages'))
|
||||
|
||||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
|
||||
@ -48,6 +53,10 @@ module.exports = {
|
||||
'json'
|
||||
],
|
||||
|
||||
moduleNameMapper: {
|
||||
[`@nuxt/(${corePackages.join('|')})(/?.*)$`]: '<rootDir>/packages/$1/src/$2'
|
||||
},
|
||||
|
||||
reporters: [
|
||||
'default',
|
||||
['jest-junit', { outputDirectory: 'reports/junit' }]
|
||||
|
@ -1,10 +1,12 @@
|
||||
import * as _commands from './commands'
|
||||
import * as _imports from './imports'
|
||||
import * as _options from './options'
|
||||
import * as commands from './commands'
|
||||
import * as imports from './imports'
|
||||
import * as options from './options'
|
||||
|
||||
export const commands = _commands
|
||||
export const imports = _imports
|
||||
export const options = _options
|
||||
export {
|
||||
commands,
|
||||
imports,
|
||||
options
|
||||
}
|
||||
|
||||
export { default as NuxtCommand } from './command'
|
||||
export { default as setup } from './setup'
|
||||
|
10
test/fixtures/cli/cli.build.config.js
vendored
10
test/fixtures/cli/cli.build.config.js
vendored
@ -1,11 +1,17 @@
|
||||
import consola from 'consola'
|
||||
|
||||
export default {
|
||||
test: true,
|
||||
mode: 'spa',
|
||||
hooks (hook) {
|
||||
hook('build:done', () => {
|
||||
process.stdout.write('Compiled successfully')
|
||||
consola.log('Compiled successfully')
|
||||
})
|
||||
hook('listen', (server, { port, host }) => {
|
||||
process.stdout.write(`Listening on http://${host}:${port}`)
|
||||
consola.log(`Listening on http://${host}:${port}`)
|
||||
})
|
||||
},
|
||||
build: {
|
||||
terser: false
|
||||
}
|
||||
}
|
||||
|
29
test/fixtures/cli/cli.build.test.js
vendored
29
test/fixtures/cli/cli.build.test.js
vendored
@ -1,21 +1,20 @@
|
||||
import { exec } from 'child_process'
|
||||
import { resolve } from 'path'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const execify = promisify(exec)
|
||||
const rootDir = __dirname
|
||||
const nuxtBin = resolve(__dirname, '../../../packages/cli/bin/nuxt.js')
|
||||
import { NuxtCommand, commands } from '@nuxt/cli'
|
||||
import consola from 'consola'
|
||||
|
||||
describe('cli build', () => {
|
||||
test.skip('nuxt build', async () => {
|
||||
const { stdout } = await execify(`node -r esm ${nuxtBin} build ${rootDir} -c cli.build.config.js`)
|
||||
test('nuxt build', async () => {
|
||||
const buildCommand = await commands.default('build')
|
||||
|
||||
expect(stdout.includes('Compiled successfully')).toBe(true)
|
||||
}, 80000)
|
||||
const argv = [
|
||||
__dirname,
|
||||
'--no-force-exit',
|
||||
'-c',
|
||||
'cli.build.config.js'
|
||||
]
|
||||
|
||||
test.skip('nuxt build -> error config', async () => {
|
||||
await expect(execify(`node -r esm ${nuxtBin} build ${rootDir} -c config.js`)).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining('Could not load config file: config.js')
|
||||
})
|
||||
const cmd = new NuxtCommand(buildCommand, argv)
|
||||
await expect(cmd.run()).resolves.toBeUndefined()
|
||||
|
||||
expect(consola.log).toBeCalledWith('Compiled successfully')
|
||||
})
|
||||
})
|
||||
|
9
test/fixtures/cli/cli.gen.config.js
vendored
9
test/fixtures/cli/cli.gen.config.js
vendored
@ -1,3 +1,5 @@
|
||||
import consola from 'consola'
|
||||
|
||||
export default {
|
||||
test: true,
|
||||
buildDir: '.nuxt-generate/build',
|
||||
@ -7,10 +9,13 @@ export default {
|
||||
hooks (hook) {
|
||||
hook('generate:done', (generator, errors) => {
|
||||
if (!errors || errors.length === 0) {
|
||||
process.stdout.write('Generated successfully')
|
||||
consola.log('Generated successfully')
|
||||
} else {
|
||||
process.stderr.write('Generated failed')
|
||||
consola.log('Generated failed')
|
||||
}
|
||||
})
|
||||
},
|
||||
build: {
|
||||
terser: false
|
||||
}
|
||||
}
|
||||
|
27
test/fixtures/cli/cli.gen.test.js
vendored
27
test/fixtures/cli/cli.gen.test.js
vendored
@ -1,15 +1,20 @@
|
||||
import { exec } from 'child_process'
|
||||
import { resolve } from 'path'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const execify = promisify(exec)
|
||||
const rootDir = __dirname
|
||||
const nuxtBin = resolve(__dirname, '../../../packages/cli/bin/nuxt.js')
|
||||
import { NuxtCommand, commands } from '@nuxt/cli'
|
||||
import consola from 'consola'
|
||||
|
||||
describe('cli generate', () => {
|
||||
test.skip('nuxt generate', async () => {
|
||||
const { stdout } = await execify(`node -r esm ${nuxtBin} generate ${rootDir} -c cli.gen.config.js`)
|
||||
test('nuxt generate', async () => {
|
||||
const generateCommand = await commands.default('generate')
|
||||
|
||||
expect(stdout.includes('Generated successfully')).toBe(true)
|
||||
}, 80000)
|
||||
const argv = [
|
||||
__dirname,
|
||||
'--no-force-exit',
|
||||
'-c',
|
||||
'cli.gen.config.js'
|
||||
]
|
||||
|
||||
const cmd = new NuxtCommand(generateCommand, argv)
|
||||
await expect(cmd.run()).resolves.toBeUndefined()
|
||||
|
||||
expect(consola.log).toBeCalledWith('Generated successfully')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user