diff --git a/test/csr.test.js b/test/csr.test.js index c3a7cb2e..ef3fe4ec 100644 --- a/test/csr.test.js +++ b/test/csr.test.js @@ -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({ @@ -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') + } }) }) diff --git a/test/ssr.test.js b/test/ssr.test.js index 7b8f1e7e..644ee5f2 100644 --- a/test/ssr.test.js +++ b/test/ssr.test.js @@ -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') + } }) })