diff --git a/README.md b/README.md index 8c4b04e..4b39824 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,11 @@ See examples below for details. See [cypress/integration/options-spec.js](cypress/integration/options-spec.js) for examples of options. -* `vue` - path or URL to the Vue library to load. By default, will -try to load `../node_modules/vue/dist/vue.js`, but you can pass your -own path or URL. +* `mountId` - specify root Vue app mount element ID. Defaults to `app`. ```js const options = { - vue: 'https://unpkg.com/vue' + mountId: 'rootApp' // div#rootApp } beforeEach(mountVue(/* my Vue code */, options)) ``` @@ -71,12 +69,25 @@ beforeEach(mountVue(/* my Vue code */, options)) place to load additional libraries, polyfills and styles. ```js -const vue = '../node_modules/vue/dist/vue.js' +const polyfill = '../node_modules/mypolyfill/dist/polyfill.js' const options = { - html: `
` + html: `` +} +beforeEach(mountVue(/* my Vue code */, options)) +``` + +* `vue` **[DEPRECATED]** - path or URL to the Vue library to load. By default, will +try to load `../node_modules/vue/dist/vue.js`, but you can pass your +own path or URL. + +```js +const options = { + vue: 'https://unpkg.com/vue' } beforeEach(mountVue(/* my Vue code */, options)) ``` +> #### Deprecation Warning +> `vue` option has been deprecated. `node_modules/vue/dist/vue` is always used. ### Global Vue extensions diff --git a/components/.babelrc b/components/.babelrc new file mode 100644 index 0000000..02e7f24 --- /dev/null +++ b/components/.babelrc @@ -0,0 +1,5 @@ +{ + "plugins": [ + "transform-object-rest-spread" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index f0f8ed6..35f703a 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "generateNotes": "github-post-release" }, "devDependencies": { + "babel-plugin-transform-object-rest-spread": "6.26.0", "ban-sensitive-files": "1.9.2", "css-loader": "0.28.7", "cypress": "1.4.1", @@ -86,7 +87,6 @@ "semantic-action": "1.1.0", "simple-commit-message": "3.3.2", "standard": "10.0.3", - "vue": "2.5.13", "vue-loader": "13.6.1", "vue-template-compiler": "2.5.13", "vuex": "3.0.1" @@ -100,6 +100,7 @@ }, "dependencies": { "@cypress/webpack-preprocessor": "1.1.2", - "common-tags": "1.6.0" + "common-tags": "1.6.0", + "vue": "2.5.13" } } diff --git a/src/index.js b/src/index.js index 1483a37..93bc350 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,17 @@ +const Vue = require('vue/dist/vue') const { stripIndent } = require('common-tags') +// mountVue options +const defaultOptions = ['html', 'vue', 'base', 'mountId', 'extensions'] + +// default mount point element ID for root Vue instance +const defaultMountId = 'app' + +const parentDocument = window.parent.document +const projectName = Cypress.config('projectName') +const appIframeId = `Your App: '${projectName}'` +const appIframe = parentDocument.getElementById(appIframeId) + // having weak reference to styles prevents garbage collection // and "losing" styles when the next test starts const stylesCache = new Map() @@ -23,10 +35,6 @@ const copyStyles = component => { return } - const parentDocument = window.parent.document - const projectName = Cypress.config('projectName') - const appIframeId = `Your App: '${projectName}'` - const appIframe = parentDocument.getElementById(appIframeId) const head = appIframe.contentDocument.querySelector('head') styles.forEach(style => { head.appendChild(style) @@ -42,59 +50,20 @@ const deleteCachedConstructors = component => { Cypress._.values(component.components).forEach(deleteConstructor) } -const getVuePath = options => - options.vue || options.vuePath || '../node_modules/vue/dist/vue.js' - -const getVuexPath = options => options.vuex || options.vuexPath - const getPageHTML = options => { - if (options.html) { - return options.html - } - const vue = getVuePath(options) - let vuex = getVuexPath(options) - if (vuex) { - vuex = `` - } - - // note: add "base" tag to force loading static assets - // from the server, not from the "spec" file URL - if (options.base) { - if (vue.startsWith('.')) { - console.error( - 'You are using base tag %s and relative Vue path %s', - options.base, - vue - ) - console.error('the relative path might NOT work') - console.error( - 'maybe pass Vue url using "https://unpkg.com/vue/dist/vue.js"' - ) - } - return stripIndent` - - -