Skip to content

Commit

Permalink
test: fill out additional test targets (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 16, 2021
1 parent 30dcff2 commit 2ca9edc
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
48 changes: 45 additions & 3 deletions test/csr.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { join } from 'path'
import { setupTest, get } from '@nuxt/test-utils'
import { readFile } from 'fs-extra'
import { setupTest, get, getContext } from '@nuxt/test-utils'

describe('module', () => {
describe('ssr: false, dev mode', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
Expand All @@ -14,6 +15,47 @@ describe('module', () => {

test('render', async () => {
const { body } = await get('/')
expect(body).toContain('nuxt-color-mode')
expect(body).toContain('nuxt-color-mode-script')
})
})

describe('ssr: false, target: server, prod mode', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
server: true,
build: true,
rootDir,
config: {
ssr: false,
target: 'server'
}
})

test('render', async () => {
const { body } = await get('/')
expect(body).toContain('nuxt-color-mode-script')
})
})

describe('ssr: false, target: static, generated files', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
generate: true,
rootDir,
config: {
ssr: false
}
})

test('generated file', async () => {
const { nuxt } = getContext()
const generateDir = nuxt.options.generate.dir
const files = ['index.html', '200.html']
for (const file of files) {
const contents = await readFile(join(generateDir, file), 'utf-8')
expect(contents).toMatch('nuxt-color-mode-script')
}
})
})
55 changes: 51 additions & 4 deletions test/ssr.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,63 @@
import { join } from 'path'
import { setupTest, get } from '@nuxt/test-utils'
import { readFile } from 'fs-extra'
import { setupTest, get, getContext } from '@nuxt/test-utils'

describe('module', () => {
describe('ssr: true, dev mode', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
server: true,
rootDir
rootDir,
config: {
ssr: true,
target: 'static'
}
})

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

describe('ssr: true, target: server, prod mode', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
server: true,
build: true,
rootDir,
config: {
ssr: true,
target: 'server'
}
})

test('render', async () => {
const { body } = await get('/')
expect(body).toContain('nuxt-color-mode-script')
})
})

describe('ssr: true, target: static, generated files', () => {
const rootDir = join(__dirname, '..', 'example')

setupTest({
generate: true,
rootDir,
config: {
ssr: true,
target: 'static'
}
})

test('generated file', async () => {
const { nuxt } = getContext()
const generateDir = nuxt.options.generate.dir
const files = ['index.html', '200.html']
for (const file of files) {
const contents = await readFile(join(generateDir, file), 'utf-8')
expect(contents).toMatch('nuxt-color-mode-script')
}
})
})

0 comments on commit 2ca9edc

Please sign in to comment.