Skip to content

Commit

Permalink
test: migrate to @nuxt/test-utils (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 16, 2021
1 parent 449b51e commit 30dcff2
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 319 deletions.
5 changes: 1 addition & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testEnvironment: 'node',
preset: '@nuxt/test-utils',
collectCoverage: true,
collectCoverageFrom: [
'lib/module.js',
Expand All @@ -10,8 +10,5 @@ module.exports = {
'^~~$': '<rootDir>',
'^@@$': '<rootDir>',
'^@/(.*)$': '<rootDir>/lib/$1'
},
transform: {
'^.+\\.js$': 'babel-jest'
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"@babel/preset-env": "^7.13.10",
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@nuxt/test-utils": "^0.2.2",
"@nuxt/types": "^2.15.3",
"@nuxtjs/eslint-config": "^6.0.0",
"@nuxtjs/module-test-utils": "^1.6.3",
"@nuxtjs/svg": "^0.1.12",
"babel-eslint": "latest",
"babel-jest": "^27.0.2",
Expand Down
30 changes: 9 additions & 21 deletions test/csr.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { join } from 'path'
import { setup, get } from '@nuxtjs/module-test-utils'
import colorModeModule from '../'
import { setupTest, get } from '@nuxt/test-utils'

describe('module', () => {
let nuxt
const rootDir = join(__dirname, '..', 'example')

beforeAll(async () => {
const rootDir = join(__dirname, '..', 'example')

const config = {
ssr: false,
rootDir,
modules: [
'@nuxtjs/svg',
colorModeModule
]
setupTest({
server: true,
rootDir,
config: {
ssr: false
}

nuxt = (await setup(config)).nuxt
}, 60000)

afterAll(async () => {
await nuxt.close()
})

test('render', async () => {
const html = await get('/')
expect(html).toContain('nuxt-color-mode')
const { body } = await get('/')
expect(body).toContain('nuxt-color-mode')
})
})
28 changes: 7 additions & 21 deletions test/ssr.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import { join } from 'path'
import { setup, get } from '@nuxtjs/module-test-utils'
import colorModeModule from '../'
import { setupTest, get } from '@nuxt/test-utils'

describe('module', () => {
let nuxt
const rootDir = join(__dirname, '..', 'example')

beforeAll(async () => {
const rootDir = join(__dirname, '..', 'example')

const config = {
rootDir,
modules: [
'@nuxtjs/svg',
colorModeModule
]
}

nuxt = (await setup(config)).nuxt
}, 60000)

afterAll(async () => {
await nuxt.close()
setupTest({
server: true,
rootDir
})

test('render', async () => {
const html = await get('/')
expect(html).toContain('@nuxtjs/color-mode')
const { body } = await get('/')
expect(body).toContain('@nuxtjs/color-mode')
})
})
Loading

0 comments on commit 30dcff2

Please sign in to comment.