Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jul 17, 2020
1 parent a8ed6ca commit 27c991a
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 20 deletions.
20 changes: 20 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { setup, loadConfig, get } = require('@nuxtjs/module-test-utils')

describe('basic', () => {
let nuxt

beforeAll(async () => {
({ nuxt } = (await setup(loadConfig(__dirname, 'basic'))))
}, 60000)

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

test('render', async () => {
const html = await get('/')
expect(html).toContain('<link data-n-head="ssr" rel="dns-prefetch" href="https://fonts.gstatic.com/">')
expect(html).toContain('<link data-n-head="ssr" rel="preconnect" href="https://fonts.gstatic.com/" crossorigin="true">')
expect(html).toContain('<link data-n-head="ssr" rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto&amp;family=Lato">')
})
})
28 changes: 28 additions & 0 deletions test/download.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { join } = require('path')
const del = require('del')
const { setup, loadConfig, get } = require('@nuxtjs/module-test-utils')

describe('download', () => {
let nuxt

beforeAll(async () => {
({ nuxt } = (await setup(loadConfig(__dirname, 'download'))))
}, 60000)

afterAll(async () => {
await nuxt.close()
await del(join(nuxt.options.srcDir, nuxt.options.dir.assets))
})

test('render', async () => {
const html = await get('/')
expect(html).not.toContain('<link data-n-head="ssr" rel="dns-prefetch" href="https://fonts.gstatic.com/">')
expect(html).not.toContain('<link data-n-head="ssr" rel="preconnect" href="https://fonts.gstatic.com/" crossorigin="true">')
expect(html).not.toContain('<link data-n-head="ssr" rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto">')
})

test('css inject', () => {
expect(nuxt.options.css).toHaveLength(1)
expect(nuxt.options.css[0]).toContain('css/fonts.css')
})
})
9 changes: 7 additions & 2 deletions example/nuxt.config.js → test/fixture/basic/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module.exports = {
rootDir: __dirname,
buildModules: [
{ handler: require('../') }
{ handler: require('../../../') }
],
head: {
link: [
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Roboto&display=swap' }
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Lato' }
]
},
googleFonts: {
families: {
Roboto: true
}
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions test/fixture/download/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
rootDir: __dirname,
buildModules: [
{ handler: require('../../../') }
],
googleFonts: {
download: true,
families: {
Roboto: true
}
}
}
11 changes: 11 additions & 0 deletions test/fixture/download/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
Works!
</div>
</template>

<script>
export default {
}
</script>
6 changes: 6 additions & 0 deletions test/fixture/warn/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
rootDir: __dirname,
buildModules: [
{ handler: require('../../../') }
]
}
11 changes: 11 additions & 0 deletions test/fixture/warn/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
Works!
</div>
</template>

<script>
export default {
}
</script>
18 changes: 0 additions & 18 deletions test/module.test.js

This file was deleted.

24 changes: 24 additions & 0 deletions test/warn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { setup, loadConfig } = require('@nuxtjs/module-test-utils')
const logger = require('../lib/logger')

logger.mockTypes(() => jest.fn())

describe('warn', () => {
let nuxt

beforeAll(async () => {
({ nuxt } = (await setup(loadConfig(__dirname, 'warn'))))
}, 60000)

beforeEach(() => {
logger.clear()
})

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

test('should warn if no provided fonts', () => {
expect(logger.warn).toHaveBeenCalledWith('No provided fonts.')
})
})

0 comments on commit 27c991a

Please sign in to comment.