diff --git a/package.json b/package.json index 78b37140e..7312292b6 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,10 @@ "access": "public" }, "scripts": { - "dev:basic": "nuxt -c ./test/fixtures/basic/nuxt.config.js", + "dev:basic": "nuxt -c ./test/fixture/basic/nuxt.config.js", "lint": "eslint src test", "test": "yarn test:fixtures && yarn test:types", - "test:fixtures": "jest test/fixtures", + "test:fixtures": "jest test", "test:types": "tsc -p types/test", "release": "standard-version && git push --follow-tags && npm publish", "docs:dev": "vuepress dev docs", @@ -63,6 +63,7 @@ }, "devDependencies": { "@babel/runtime": "7.5.5", + "@nuxtjs/module-test-utils": "1.2.0", "codecov": "3.5.0", "eslint": "6.2.1", "eslint-config-standard": "14.0.0", diff --git a/test/fixtures/basic/__snapshots__/module.test.js.snap b/test/__snapshots__/module.test.js.snap similarity index 94% rename from test/fixtures/basic/__snapshots__/module.test.js.snap rename to test/__snapshots__/module.test.js.snap index 5f3a58f8f..472d1ad6b 100644 --- a/test/fixtures/basic/__snapshots__/module.test.js.snap +++ b/test/__snapshots__/module.test.js.snap @@ -4,7 +4,7 @@ exports[`basic / contains EN text, link to /fr/ & link /about-us 1`] = ` " - +
Français
@@ -19,7 +19,7 @@ exports[`basic /about-us contains EN text, link to /fr/a-propos & link / 1`] = ` " - +
@@ -34,7 +34,7 @@ exports[`basic /dynamicNested/1/2/3 contains link to /fr/imbrication-dynamique/1 " - +
@@ -49,7 +49,7 @@ exports[`basic /fr contains FR text, link to / & link to /fr/a-propos 1`] = ` " - +
@@ -64,7 +64,7 @@ exports[`basic /fr/a-propos contains FR text, link to /about-us & link to /fr/ 1 " - +
@@ -79,7 +79,7 @@ exports[`basic /fr/imbrication-dynamique/1/2/3 contains link to /dynamicNested/1 " - +
@@ -94,7 +94,7 @@ exports[`basic /fr/notlocalized contains FR text 1`] = ` " - +
@@ -107,6 +107,6 @@ exports[`basic /fr/notlocalized contains FR text 1`] = ` exports[`basic sets SEO metadata properly 1`] = ` " - + " `; diff --git a/test/fixtures/basic/components/LangSwitcher.vue b/test/fixture/basic/components/LangSwitcher.vue similarity index 100% rename from test/fixtures/basic/components/LangSwitcher.vue rename to test/fixture/basic/components/LangSwitcher.vue diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixture/basic/nuxt.config.js similarity index 100% rename from test/fixtures/basic/nuxt.config.js rename to test/fixture/basic/nuxt.config.js diff --git a/test/fixtures/basic/pages/about.vue b/test/fixture/basic/pages/about.vue similarity index 100% rename from test/fixtures/basic/pages/about.vue rename to test/fixture/basic/pages/about.vue diff --git a/test/fixtures/basic/pages/dynamicNested/_category.vue b/test/fixture/basic/pages/dynamicNested/_category.vue similarity index 100% rename from test/fixtures/basic/pages/dynamicNested/_category.vue rename to test/fixture/basic/pages/dynamicNested/_category.vue diff --git a/test/fixtures/basic/pages/dynamicNested/_category/_subCategory/_id.vue b/test/fixture/basic/pages/dynamicNested/_category/_subCategory/_id.vue similarity index 100% rename from test/fixtures/basic/pages/dynamicNested/_category/_subCategory/_id.vue rename to test/fixture/basic/pages/dynamicNested/_category/_subCategory/_id.vue diff --git a/test/fixtures/basic/pages/dynamicNested/_category/_subCategory/index.vue b/test/fixture/basic/pages/dynamicNested/_category/_subCategory/index.vue similarity index 100% rename from test/fixtures/basic/pages/dynamicNested/_category/_subCategory/index.vue rename to test/fixture/basic/pages/dynamicNested/_category/_subCategory/index.vue diff --git a/test/fixtures/basic/pages/dynamicNested/index.vue b/test/fixture/basic/pages/dynamicNested/index.vue similarity index 100% rename from test/fixtures/basic/pages/dynamicNested/index.vue rename to test/fixture/basic/pages/dynamicNested/index.vue diff --git a/test/fixtures/basic/pages/fr/notlocalized.vue b/test/fixture/basic/pages/fr/notlocalized.vue similarity index 100% rename from test/fixtures/basic/pages/fr/notlocalized.vue rename to test/fixture/basic/pages/fr/notlocalized.vue diff --git a/test/fixtures/basic/pages/index.vue b/test/fixture/basic/pages/index.vue similarity index 100% rename from test/fixtures/basic/pages/index.vue rename to test/fixture/basic/pages/index.vue diff --git a/test/fixtures/basic/pages/posts.vue b/test/fixture/basic/pages/posts.vue similarity index 100% rename from test/fixtures/basic/pages/posts.vue rename to test/fixture/basic/pages/posts.vue diff --git a/test/fixtures/basic/pages/posts/_slug.vue b/test/fixture/basic/pages/posts/_slug.vue similarity index 100% rename from test/fixtures/basic/pages/posts/_slug.vue rename to test/fixture/basic/pages/posts/_slug.vue diff --git a/test/fixtures/basic/pages/posts/index.vue b/test/fixture/basic/pages/posts/index.vue similarity index 100% rename from test/fixtures/basic/pages/posts/index.vue rename to test/fixture/basic/pages/posts/index.vue diff --git a/test/fixtures/basic/store/index.js b/test/fixture/basic/store/index.js similarity index 100% rename from test/fixtures/basic/store/index.js rename to test/fixture/basic/store/index.js diff --git a/test/fixtures/basic/module.test.js b/test/module.test.js similarity index 86% rename from test/fixtures/basic/module.test.js rename to test/module.test.js index 6fa5fe1d6..52ade4ed5 100644 --- a/test/fixtures/basic/module.test.js +++ b/test/module.test.js @@ -1,26 +1,18 @@ jest.setTimeout(60000) -process.env.PORT = process.env.PORT || 5060 process.env.NODE_ENV = 'production' -const { Nuxt, Builder } = require('nuxt') -const request = require('request-promise-native') +const { setup, loadConfig, get, url } = require('@nuxtjs/module-test-utils') const { JSDOM } = require('jsdom') -const config = require('./nuxt.config') +const { cleanUpScripts } = require('./utils') -const { cleanUpScripts } = require('../../utils') - -const url = path => `http://localhost:${process.env.PORT}${path}` -const get = path => request(url(path)) const getDom = html => (new JSDOM(html)).window.document describe('basic', () => { let nuxt beforeAll(async () => { - nuxt = new Nuxt(config) - await new Builder(nuxt).build() - await nuxt.listen(process.env.PORT) + nuxt = (await setup(loadConfig(__dirname, 'basic'))).nuxt }) afterAll(async () => { @@ -143,13 +135,13 @@ describe('hash mode', () => { let nuxt beforeAll(async () => { - config.router = { - mode: 'hash' + const override = { + router: { + mode: 'hash' + } } - nuxt = new Nuxt(config) - await new Builder(nuxt).build() - await nuxt.listen(process.env.PORT) + nuxt = (await setup(loadConfig(__dirname, 'basic', override))).nuxt }) afterAll(async () => { @@ -167,13 +159,13 @@ describe('with router base', () => { let nuxt beforeAll(async () => { - config.router = { - base: '/app/' + const override = { + router: { + base: '/app/' + } } - nuxt = new Nuxt(config) - await new Builder(nuxt).build() - await nuxt.listen(process.env.PORT) + nuxt = (await setup(loadConfig(__dirname, 'basic', override))).nuxt }) afterAll(async () => { diff --git a/yarn.lock b/yarn.lock index 9d1b553b3..232d5cc5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1176,6 +1176,15 @@ webpack-node-externals "^1.7.2" webpackbar "^4.0.0" +"@nuxtjs/module-test-utils@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@nuxtjs/module-test-utils/-/module-test-utils-1.2.0.tgz#017ddc3ab91f649defebd945054e28f26f506a3a" + integrity sha512-+N+JoRTCRz5/6RhEWGi9tCD18SSzCzUHWPuZKN1A1CwJ3IsdYPvynmfUjHf5X+lnnvRKQ0u2kiVGz0blNLudew== + dependencies: + get-port latest + request latest + request-promise-native latest + "@nuxtjs/youch@^4.2.3": version "4.2.3" resolved "https://registry.yarnpkg.com/@nuxtjs/youch/-/youch-4.2.3.tgz#36f8b22df5a0efaa81373109851e1d857aca6bed" @@ -4966,6 +4975,13 @@ get-pkg-repo@^1.0.0: parse-github-repo-url "^1.3.0" through2 "^2.0.0" +get-port@latest: + version "5.0.0" + resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.0.0.tgz#aa22b6b86fd926dd7884de3e23332c9f70c031a6" + integrity sha512-imzMU0FjsZqNa6BqOjbbW6w5BivHIuQKopjpPqcnx0AVHJQKCxK1O+Ab3OrVXhrekqfVMjwA9ZYu062R+KcIsQ== + dependencies: + type-fest "^0.3.0" + get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" @@ -9370,7 +9386,7 @@ request-promise-core@1.1.2: dependencies: lodash "^4.17.11" -request-promise-native@^1.0.5, request-promise-native@^1.0.7: +request-promise-native@^1.0.5, request-promise-native@^1.0.7, request-promise-native@latest: version "1.0.7" resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.7.tgz#a49868a624bdea5069f1251d0a836e0d89aa2c59" integrity sha512-rIMnbBdgNViL37nZ1b3L/VfPOpSi0TqVDQPAvO6U14lMzOLrt5nilxCQqtDKhZeDiW0/hkCXGoQjhgJd/tCh6w== @@ -9379,7 +9395,7 @@ request-promise-native@^1.0.5, request-promise-native@^1.0.7: stealthy-require "^1.1.1" tough-cookie "^2.3.3" -request@^2.87.0, request@^2.88.0: +request@^2.87.0, request@^2.88.0, request@latest: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg== @@ -10663,6 +10679,11 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" +type-fest@^0.3.0: + version "0.3.1" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1" + integrity sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ== + type-fest@^0.5.2: version "0.5.2" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.5.2.tgz#d6ef42a0356c6cd45f49485c3b6281fc148e48a2"