Last active
January 18, 2020 23:16
-
-
Save brandonaaskov/fee610305e065855292a10791035d426 to your computer and use it in GitHub Desktop.
Jest setup file for testing nuxt stores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Nuxt, Builder } from "nuxt" | |
import nuxtConfig from "./nuxt.config" | |
// these boolean switches turn off the build for all but the store | |
const resetConfig = { | |
loading: false, | |
loadingIndicator: false, | |
fetch: { | |
client: false, | |
server: false | |
}, | |
features: { | |
store: true, | |
layouts: false, | |
meta: false, | |
middleware: false, | |
transitions: false, | |
deprecations: false, | |
validate: false, | |
asyncData: false, | |
fetch: false, | |
clientOnline: false, | |
clientPrefetch: false, | |
clientUseUrl: false, | |
componentAliases: false, | |
componentClientOnly: false | |
}, | |
build: { | |
indicator: false, | |
terser: false | |
} | |
} | |
// we take our nuxt config, lay the resets on top of it, | |
// and lastly we apply the non-boolean overrides | |
const config = Object.assign({}, nuxtConfig, resetConfig, { | |
mode: "spa", | |
srcDir: nuxtConfig.srcDir, | |
ignore: ["**/components/**/*", "**/layouts/**/*", "**/pages/**/*"] | |
}) | |
const buildNuxt = async () => { | |
const nuxt = new Nuxt(config) | |
await new Builder(nuxt).build() | |
return nuxt | |
} | |
module.exports = async () => { | |
const nuxt = await buildNuxt() | |
// we surface this path as an env var now | |
// so we can import the store dynamically later on | |
process.env.buildDir = nuxt.options.buildDir | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment