From 75350cdd78d17e565b6c58d6c1aaa00c5146cbae Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sat, 7 Oct 2017 12:37:52 +0330 Subject: [PATCH] test: add tests for spa --- test/fixtures/spa/layouts/custom.vue | 7 ++++++ test/fixtures/spa/nuxt.config.js | 5 ++++ test/fixtures/spa/pages/index.vue | 15 ++++++++++++ test/spa.test.js | 36 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 test/fixtures/spa/layouts/custom.vue create mode 100644 test/fixtures/spa/nuxt.config.js create mode 100644 test/fixtures/spa/pages/index.vue create mode 100755 test/spa.test.js diff --git a/test/fixtures/spa/layouts/custom.vue b/test/fixtures/spa/layouts/custom.vue new file mode 100644 index 0000000000..5a02389c29 --- /dev/null +++ b/test/fixtures/spa/layouts/custom.vue @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/test/fixtures/spa/nuxt.config.js b/test/fixtures/spa/nuxt.config.js new file mode 100644 index 0000000000..a17da47b52 --- /dev/null +++ b/test/fixtures/spa/nuxt.config.js @@ -0,0 +1,5 @@ +module.exports = { + rootDir: __dirname, + mode: 'spa', + dev: false +} diff --git a/test/fixtures/spa/pages/index.vue b/test/fixtures/spa/pages/index.vue new file mode 100644 index 0000000000..e903a5128f --- /dev/null +++ b/test/fixtures/spa/pages/index.vue @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/test/spa.test.js b/test/spa.test.js new file mode 100755 index 0000000000..4dac8b0370 --- /dev/null +++ b/test/spa.test.js @@ -0,0 +1,36 @@ +import test from 'ava' +import { resolve } from 'path' +import { Nuxt, Builder } from '../index.js' + +let nuxt = null + +const port = 4004 +const url = (route) => 'http://localhost:' + port + route + +const renderRoute = async _url => { + const window = await nuxt.renderAndGetWindow(url(_url)) + const html = window.document.body.innerHTML + return { window, html } +} + +// Init nuxt.js and create server listening on localhost:4000 +test.before('Init Nuxt.js', async t => { + nuxt = new Nuxt(require('./fixtures/spa/nuxt.config')) + await new Builder(nuxt).build() + await nuxt.listen(port, 'localhost') +}) + +test('/ (basic spa)', async t => { + const { html } = await renderRoute('/') + t.true(html.includes('Hello SPA!')) +}) + +test('/ (custom layout)', async t => { + const { html } = await renderRoute('/') + t.true(html.includes('Custom layout')) +}) + +// Close server and ask nuxt to stop listening to file changes +test.after('Closing server and nuxt.js', t => { + nuxt.close() +})