Skip to content

Commit

Permalink
feat: nuxt 2.2 compat (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL committed Nov 8, 2018
1 parent 4841dc4 commit c312b2d
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function nuxtStyledResources() {
const wrappedValue = Array.isArray(value) ? value : [value]
normalizedObject[key] = wrappedValue.reduce((acc, path) => {
// Try to resolve alias, if not possible join with srcDir
path = this.nuxt.resolver.resolveAlias(path)
path = (this.nuxt.resolver || this.nuxt).resolveAlias(path)
// Try to glob (if it's a glob
path = glob.sync(path)
// Flatten this (glob could produce an array
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"less": "^3.8.1",
"less-loader": "^4.1.0",
"node-sass": "^4.10.0",
"nuxt": "^2.2.0",
"nuxt-edge": "^2.3.0-25667110.ec55975",
"sass-loader": "^7.1.0",
"standard-version": "^4.4.0",
Expand Down
108 changes: 56 additions & 52 deletions test/module.test.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,78 @@
const consola = require('consola')
const getPort = require('get-port')
const { Nuxt, Builder } = require('nuxt-edge')

const nuxtStable = require('nuxt')
const nuxtEdge = require('nuxt-edge')
jest.setTimeout(60 * 1000)

let nuxt, port

const url = route => 'http://localhost:' + port + route

describe('nuxt-style-resources', () => {
let log
const setupNuxtFn = ({ Nuxt, Builder }) => async (config) => {
const nuxt = new Nuxt(config)
await new Builder(nuxt).build()
port = await getPort()
await nuxt.listen(port)

beforeEach(() => {
log = jest.fn()
consola.clear().add({ log })
})
return nuxt
}

describe('scss', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/sass/nuxt.config'))
describe('nuxt-style-resources', () => {
describe.each([['nuxt', nuxtStable], ['nuxt-edge', nuxtEdge]])('%s', (_, nuxtImpl) => {
let log

const window = await nuxt.server.renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('.ymca{color:#333')
})
const setupNuxt = setupNuxtFn(nuxtImpl)

afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
beforeEach(() => {
log = jest.fn()
consola.clear().add({ log })
})
})
describe('stylus', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/stylus/nuxt.config'))

const window = await nuxt.server.renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('.ymca{color:#333')
})
describe('scss', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/sass/nuxt.config'))

afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
const window = await (nuxt.server || nuxt).renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('.ymca{color:#333')
})

afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
})
})
})
describe('less', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/less/nuxt.config'))
describe('stylus', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/stylus/nuxt.config'))

const window = await (nuxt.server || nuxt).renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('.ymca{color:#333')
})

const window = await nuxt.server.renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('h1{color:#0f0}')
expect(headHtml).toContain('.ymca{color:#333')
afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
})
})
describe('less', () => {
test('properly import variables', async () => {
nuxt = await setupNuxt(require('./fixture/less/nuxt.config'))

afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
const window = await (nuxt.server || nuxt).renderAndGetWindow(url('/'))
const headHtml = window.document.head.innerHTML
expect(headHtml).toContain('h1{color:#0f0}')
expect(headHtml).toContain('.ymca{color:#333')
})

afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
})
})
})
})

const setupNuxt = async (config) => {
const nuxt = new Nuxt(config)
await new Builder(nuxt).build()
port = await getPort()
await nuxt.listen(port)

return nuxt
}
Loading

0 comments on commit c312b2d

Please sign in to comment.