Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jun 27, 2019
1 parent 7101ab7 commit b260a15
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 74 deletions.
32 changes: 32 additions & 0 deletions test/dev.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jest.setTimeout(60000)

const { Nuxt, Builder } = require('nuxt-edge')
const request = require('request-promise-native')
const getPort = require('get-port')

const config = require('./fixture/nuxt.config')
config.dev = true

let nuxt, port

const url = path => `http://localhost:${port}${path}`
const get = path => request(url(path))

describe('dev', () => {
beforeAll(async () => {
nuxt = new Nuxt(config)
await nuxt.ready()
await new Builder(nuxt).build()
port = await getPort()
await nuxt.listen(port)
})

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

test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
})
})
74 changes: 0 additions & 74 deletions test/module.test.js

This file was deleted.

32 changes: 32 additions & 0 deletions test/prod.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
jest.setTimeout(60000)

const { Nuxt, Builder } = require('nuxt-edge')
const request = require('request-promise-native')
const getPort = require('get-port')

const config = require('./fixture/nuxt.config')
config.dev = false

let nuxt, port

const url = path => `http://localhost:${port}${path}`
const get = path => request(url(path))

describe('prod', () => {
beforeAll(async () => {
nuxt = new Nuxt(config)
await nuxt.ready()
await new Builder(nuxt).build()
port = await getPort()
await nuxt.listen(port)
})

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

test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
})
})
40 changes: 40 additions & 0 deletions test/warn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
jest.setTimeout(60000)

const { Nuxt } = require('nuxt-edge')
const config = require('./fixture/nuxt.config')
const logger = require('@/logger')
const { moduleExists } = require('@/utils')

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

jest.mock('@/utils', () => ({
moduleExists: jest.fn()
}))

let nuxt

describe('warn', () => {
beforeAll(async () => {
moduleExists.mockImplementation(() => false)

nuxt = new Nuxt(config)
await nuxt.ready()
})

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

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

test('should warn if not found the `stylelint` dependency', () => {
expect(moduleExists).toBeCalledWith('stylelint')
expect(moduleExists).toHaveReturnedWith(false)
expect(logger.warn).toHaveBeenCalledWith(
'The dependency `stylelint` not found.',
'Please run `yarn add stylelint --dev` or `npm install stylelint --save-dev`'
)
})
})

0 comments on commit b260a15

Please sign in to comment.