Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit 228d4ef

Browse files
committed
fix: use semantic-action
1 parent 3ca996c commit 228d4ef

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eslint.enable": false
3+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@
6161
"test": "npm run unit",
6262
"unit": "mocha src/*-spec.js",
6363
"unused-deps": "dependency-check --unused --no-dev .",
64-
"semantic-release": "semantic-release"
64+
"semantic-release": "semantic-action pre && npm publish && semantic-action post"
6565
},
6666
"release": {
6767
"analyzeCommits": "simple-commit-message"
6868
},
6969
"devDependencies": {
7070
"ban-sensitive-files": "1.9.2",
71+
"cypress": "1.4.0",
7172
"dependency-check": "2.9.2",
7273
"deps-ok": "1.2.1",
7374
"git-issues": "1.3.1",
@@ -76,7 +77,8 @@
7677
"nsp": "3.1.0",
7778
"pre-git": "3.16.0",
7879
"prettier-standard": "8.0.0",
80+
"semantic-action": "1.1.0",
7981
"standard": "10.0.3",
80-
"semantic-release": "^11.0.2"
82+
"vue": "2.5.13"
8183
}
8284
}

src/index.js

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
1-
'use strict'
1+
/* global Cypress, cy */
22

3-
module.exports = true
3+
// having weak reference to styles prevents garbage collection
4+
// and "losing" styles when the next test starts
5+
const stylesCache = new Map()
6+
7+
function copyStyles (component) {
8+
let styles
9+
if (stylesCache.has(component)) {
10+
styles = stylesCache.get(component)
11+
} else {
12+
styles = document.querySelectorAll('head style')
13+
if (styles.length) {
14+
console.log('injected %d styles', styles.length)
15+
stylesCache.set(component, styles)
16+
} else {
17+
console.log('No styles injected for this component')
18+
styles = null
19+
}
20+
}
21+
22+
if (!styles) {
23+
return
24+
}
25+
26+
const parentDocument = window.parent.document
27+
const projectName = Cypress.config('projectName')
28+
const appIframeId = `Your App: '${projectName}'`
29+
const appIframe = parentDocument.getElementById(appIframeId)
30+
const head = appIframe.contentDocument.querySelector('head')
31+
styles.forEach(style => {
32+
head.appendChild(style)
33+
})
34+
}
35+
36+
const deleteConstructor = comp => delete comp._Ctor
37+
38+
function deleteCachedConstructors (component) {
39+
if (!component.components) {
40+
return
41+
}
42+
Cypress._.values(component.components).forEach(deleteConstructor)
43+
}
44+
45+
const mountVue = component => () => {
46+
cy.visit('index.html')
47+
cy
48+
.window()
49+
.its('Vue')
50+
.then(Vue => {
51+
deleteCachedConstructors(component)
52+
Cypress.vue = new Vue(component).$mount('#app')
53+
copyStyles(component)
54+
})
55+
}
56+
57+
module.exports = mountVue
58+
59+
// export const loadAndMountMyComponent = VueComponent => () => {
60+
// cy.visit('index.html')
61+
// cy
62+
// .window()
63+
// .its('Vue')
64+
// .then(Vue => {
65+
// deleteCachedConstructors(VueComponent)
66+
// // TODO go through ITS components and delete their constructors
67+
// // wonder if there is unified list
68+
// Cypress.vue = new Vue(VueComponent).$mount('#app')
69+
// copyStyles(VueComponent)
70+
// })
71+
// }

0 commit comments

Comments
 (0)