Skip to content

Commit

Permalink
feat: add zendesk script to head and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Apr 20, 2019
1 parent 7984292 commit f9c4730
Show file tree
Hide file tree
Showing 10 changed files with 10,043 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules
.DS_Store
coverage
dist
.env
24 changes: 13 additions & 11 deletions lib/module.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { resolve } = require('path')
module.exports = function (moduleOptions) {
const options = Object.assign(
{
key: process.env.ZENDESK_KEY || '',
script: process.env.ZENDESK_SCRIPT || '//static.zdassets.com/ekr/snippet.js'
},
this.options.zendesk,
moduleOptions
)

module.exports = async function (moduleOptions) {
const options = {
...this.options['nuxt-zendesk'],
...moduleOptions
}

this.addPlugin({
src: resolve(__dirname, 'plugin.js'),
fileName: 'nuxt-zendesk.js',
options
this.options.head.script.push({
src: options.script + '?key=' + options.key,
id: 'ze-snippet',
async: true
})
}

Expand Down
4 changes: 0 additions & 4 deletions lib/plugin.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/widget.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"access": "public"
},
"scripts": {
"dev": "nuxt example",
"dev": "nuxt test/fixture",
"lint": "eslint lib test",
"test": "yarn lint && jest",
"release": "yarn test && standard-version && git push --follow-tags && npm publish"
Expand All @@ -29,6 +29,7 @@
"@babel/preset-env": "latest",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@nuxtjs/dotenv": "latest",
"@nuxtjs/eslint-config": "latest",
"babel-eslint": "latest",
"babel-jest": "latest",
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/.env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ZENDESK_KEY=
ZENDESK_SCRIPT_URL=
5 changes: 4 additions & 1 deletion example/nuxt.config.js → test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { resolve } = require('path')
require('dotenv').config({
path: resolve(__dirname, '.env')
})

module.exports = {
rootDir: resolve(__dirname, '..'),
Expand All @@ -8,6 +11,6 @@ module.exports = {
resourceHints: false
},
modules: [
{ handler: require('../') }
{ handler: require('../..') }
]
}
File renamed without changes.
3 changes: 2 additions & 1 deletion test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Nuxt, Builder } = require('nuxt-edge')
const request = require('request-promise-native')
const getPort = require('get-port')

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

let nuxt, port
Expand All @@ -28,5 +28,6 @@ describe('basic', () => {
test('render', async () => {
const html = await get('/')
expect(html).toContain('Works!')
expect(html).toContain('static.zdassets.com/ekr/snippet.js')
})
})
Loading

0 comments on commit f9c4730

Please sign in to comment.