Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Feb 1, 2018
1 parent 408cad0 commit 8418c32
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 27 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (moduleOptions) {

// Plugin
const { dst } = this.addTemplate({
src: resolve(__dirname, './auth.plugin.js'),
src: resolve(__dirname, './auth.plugin.tmpl.js'),
fileName: 'auth.plugin.js',
options
})
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
"release": "standard-version && git push --follow-tags && npm publish"
},
"eslintIgnore": [
"lib/templates"
"*.tmpl.*"
],
"files": [
"lib",
"src",
"dist",
"templates"
"lib"
],
"jest": {
"testEnvironment": "node",
Expand Down Expand Up @@ -64,6 +61,7 @@
"jest": "latest",
"jsdom": "latest",
"nuxt": "latest",
"puppeteer": "^1.0.0",
"standard-version": "latest"
}
}
2 changes: 1 addition & 1 deletion test/fixture/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ app.post('/logout', (req, res, next) => {

// Error handler
app.use((err, req, res, next) => {
console.error(err)
console.error(err) // eslint-disable-line no-console
res.status(401).send(err + '')
})

Expand Down
54 changes: 37 additions & 17 deletions test/module.test.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
process.env.PORT = process.env.PORT || 5060
process.env.NODE_ENV = 'production'

const { Nuxt, Builder } = require('nuxt')
const request = require('request-promise-native')
const puppeteer = require('puppeteer')

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

const url = path => `http://localhost:${process.env.PORT}${path}`
const get = path => request(url(path))
const url = path => `http://localhost:3000${path}`

describe('Module', () => {
describe('auth', () => {
let nuxt
let browser

beforeAll(async () => {
config.modules.unshift(function () {
// Add test specific test only hooks on nuxt life cycle
browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
})

// Build a fresh nuxt
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
// await new Builder(nuxt).build()
await nuxt.listen(process.env.PORT)
})
}, 60000)

afterAll(async () => {
// Close all opened resources
await browser.close()
await nuxt.close()
})

test('render', async () => {
let html = await get('/')
expect(html).toContain('Works!')
test('initial state', async () => {
const page = await browser.newPage()
await page.goto(url('/'))

const state = await page.evaluate(() => window.__NUXT__.state)
expect(state.auth).toEqual({ user: null, loggedIn: false })

await page.close()
})

test('login', async () => {
const page = await browser.newPage()
await page.goto(url('/'))
await page.waitForFunction('!!window.$nuxt')

const { token, user } = await page.evaluate(async () => {
await window.$nuxt.$auth.login({
data: { username: 'user', password: 'pass' }
})

return {
token: window.$nuxt.$auth.getState('token'),
user: window.$nuxt.$auth.getState('user')
}
})

expect(token).toBeDefined()
expect(user.username).toBe('user')
})
})
81 changes: 78 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ acorn@^5.0.0, acorn@^5.1.1, acorn@^5.2.1, acorn@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"

agent-base@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.0.tgz#9838b5c3392b962bad031e6a4c5e1024abec45ce"
dependencies:
es6-promisify "^5.0.0"

ajv-keywords@^2.0.0, ajv-keywords@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"
Expand Down Expand Up @@ -1553,7 +1559,7 @@ [email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

concat-stream@^1.4.10, concat-stream@^1.5.0, concat-stream@^1.6.0:
concat-stream@1.6.0, concat-stream@^1.4.10, concat-stream@^1.5.0, concat-stream@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7"
dependencies:
Expand Down Expand Up @@ -2374,10 +2380,16 @@ es6-map@^0.1.3:
es6-symbol "~3.1.1"
event-emitter "~0.3.5"

es6-promise@^4.2.4:
es6-promise@^4.0.3, es6-promise@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.4.tgz#dc4221c2b16518760bd8c39a52d8f356fc00ed29"

es6-promisify@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
dependencies:
es6-promise "^4.0.3"

es6-set@~0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1"
Expand Down Expand Up @@ -2769,6 +2781,15 @@ extract-text-webpack-plugin@^3.0.2:
schema-utils "^0.3.0"
webpack-sources "^1.0.1"

extract-zip@^1.6.5:
version "1.6.6"
resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-1.6.6.tgz#1290ede8d20d0872b429fd3f351ca128ec5ef85c"
dependencies:
concat-stream "1.6.0"
debug "2.6.9"
mkdirp "0.5.0"
yauzl "2.4.1"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
Expand Down Expand Up @@ -2799,6 +2820,12 @@ fb-watchman@^2.0.0:
dependencies:
bser "^2.0.0"

fd-slicer@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.0.1.tgz#8b5bcbd9ec327c5041bf9ab023fd6750f1177e65"
dependencies:
pend "~1.2.0"

figures@^1.5.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e"
Expand Down Expand Up @@ -3448,6 +3475,13 @@ https-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"

https-proxy-agent@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.1.1.tgz#a7ce4382a1ba8266ee848578778122d491260fd9"
dependencies:
agent-base "^4.1.0"
debug "^3.1.0"

[email protected], iconv-lite@^0.4.17, iconv-lite@~0.4.13:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
Expand Down Expand Up @@ -4702,7 +4736,7 @@ [email protected]:
version "1.4.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"

mime@^1.4.1:
mime@^1.3.4, mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"

Expand Down Expand Up @@ -4762,6 +4796,12 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"

[email protected]:
version "0.5.0"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.0.tgz#1d73076a6df986cd9344e15e71fcc05a4c9abf12"
dependencies:
minimist "0.0.8"

"mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down Expand Up @@ -5335,6 +5375,10 @@ pbkdf2@^3.0.3:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

pend@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"

performance-now@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
Expand Down Expand Up @@ -5992,6 +6036,10 @@ proxy-addr@~2.0.2:
forwarded "~0.1.2"
ipaddr.js "1.5.2"

proxy-from-env@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee"

prr@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
Expand Down Expand Up @@ -6044,6 +6092,19 @@ punycode@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"

puppeteer@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.0.0.tgz#20f3bb6ad6c6778b4d1fb750e808a29fec0a88a4"
dependencies:
debug "^2.6.8"
extract-zip "^1.6.5"
https-proxy-agent "^2.1.0"
mime "^1.3.4"
progress "^2.0.0"
proxy-from-env "^1.0.0"
rimraf "^2.6.1"
ws "^3.0.0"

q@^1.1.2, q@^1.4.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
Expand Down Expand Up @@ -7697,6 +7758,14 @@ write@^0.2.1:
dependencies:
mkdirp "^0.5.1"

ws@^3.0.0:
version "3.3.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.3.tgz#f1cf84fe2d5e901ebce94efaece785f187a228f2"
dependencies:
async-limiter "~1.0.0"
safe-buffer "~5.1.0"
ultron "~1.1.0"

ws@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-4.0.0.tgz#bfe1da4c08eeb9780b986e0e4d10eccd7345999f"
Expand Down Expand Up @@ -7786,3 +7855,9 @@ yargs@~3.10.0:
cliui "^2.1.0"
decamelize "^1.0.0"
window-size "0.1.0"

[email protected]:
version "2.4.1"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.4.1.tgz#9528f442dab1b2284e58b4379bb194e22e0c4005"
dependencies:
fd-slicer "~1.0.1"

0 comments on commit 8418c32

Please sign in to comment.