Skip to content

Commit 72f7111

Browse files
authored
setup-import-components (#102)
* add test for imported component * refactor: remove code * add rendering for normal jsx and tsx * use tsx when needed * add directives to the readme * update compiler * build with the right stuff and an example * fix types * add cypress cloud integration * fix e2e tests
1 parent e1c116a commit 72f7111

File tree

15 files changed

+145
-77
lines changed

15 files changed

+145
-77
lines changed

.github/workflows/pr.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@ jobs:
2828
- name: Build Demo
2929
run: npm run build:demo
3030

31-
- name: Test e2e
32-
run: npm run test:e2e
31+
- name: Run E2E Test
32+
uses: cypress-io/github-action@v5
33+
with:
34+
start: npm run preview
35+
record: true
36+
browser: chrome
37+
env:
38+
# Recommended: pass the GitHub token lets this action correctly
39+
# determine the unique run id necessary to re-run the checks
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}

.github/workflows/release.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ jobs:
3333
run: npm run build:demo
3434

3535
- name: Run E2E Test
36-
run: npm run test:e2e
36+
uses: cypress-io/github-action@v5
37+
with:
38+
start: npm run preview
39+
record: true
40+
browser: chrome
41+
env:
42+
# Recommended: pass the GitHub token lets this action correctly
43+
# determine the unique run id necessary to re-run the checks
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
3746

3847
- name: Deploy to vue-live.surge.sh
3948
if: ${{ github.ref == 'refs/heads/master' }}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ export default {
178178
</script>
179179
```
180180

181+
### `directives`
182+
183+
**Type** Object:
184+
185+
- key: registration name
186+
- value: VueJs directive object
187+
188+
You can use this prop in the same fashion as `components` above.
189+
181190
### `requires`
182191

183192
**Type** Object:

cypress.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from "cypress";
22

33
export default defineConfig({
4+
projectId: 'wbesaj',
45
e2e: {
56
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
67
baseUrl: "http://localhost:4173",

cypress/e2e/LiveRefresh.cy.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@ describe("Live Refresh", () => {
1010
});
1111

1212
it("changes the render after code change", () => {
13+
const textToReplace = "inline component";
14+
const textReplaced = "red component";
15+
1316
cy.get("@preview")
14-
.find(".v3dp__datepicker input")
15-
.should("not.have.value", "");
17+
.get("[data-cy=my-button]")
18+
.should("have.text", textToReplace);
1619

17-
const codeToDelete = ' v-model="today"/>';
1820
cy.get("@container")
19-
.find(".prism-editor-wrapper textarea")
20-
.type(`${"{backspace}".repeat(codeToDelete.length)}/>`);
21+
.find(".prism-editor-wrapper textarea").as("editor");
22+
23+
cy.get("@editor").invoke("val")
24+
.then((val) => {
25+
cy.get("@editor")
26+
.clear()
27+
.invoke('val', `${val}`.replace(textToReplace, textReplaced))
28+
.trigger('input');
2129

22-
cy.get("@preview").find(".v3dp__datepicker input").should("have.value", "");
30+
cy.get("@preview")
31+
.get("[data-cy=my-button]")
32+
.should("have.text", textReplaced);
33+
});
2334
});
2435
});

demo/App.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<div class="livebox">
1616
<div class="hint">You can edit this <span>-></span></div>
17-
<VueLive :editorProps="{ lineNumbers: true }" :code="codeTemplate" :layout="CustomLayout"
17+
<VueLive :editorProps="{ lineNumbers: true }" :code="codeSfcSetup" :layout="CustomLayout"
1818
:components="registeredComponents" @error="(e: any) => log('Error on first example', e)" />
1919
</div>
2020

@@ -27,8 +27,8 @@
2727
file components as well
2828
</p>
2929
<VueLive :code="codeSfc" :layout="CustomLayout" />
30-
<h2>SFC with setup</h2>
31-
<VueLive :code="codeSfcSetup" :layout="CustomLayout" />
30+
<h2>VSG partial mode or pure template</h2>
31+
<VueLive :code="codeTemplate" :layout="CustomLayout" />
3232
<h2>Pure JavaScript code</h2>
3333
<p>Or if you prefer to, use the <b>new Vue()</b> format</p>
3434
<VueLive :code="codeJs" :layout="CustomLayout" />
@@ -65,6 +65,9 @@
6565
<h2>JSX</h2>
6666
<VueLive :code="realjsx" :layout="CustomLayout" :jsx="true" />
6767

68+
<h2>TSX</h2>
69+
<VueLive :code="blobtsx" :layout="CustomLayout" lang="tsx" :jsx="true" />
70+
6871
<h2>Double Root</h2>
6972
<VueLive :code="doubleRoot" :layout="CustomLayout" />
7073

@@ -92,6 +95,7 @@ import codeSfc from "./assets/Button.vue?raw";
9295
import codeSfcSetup from "./assets/ButtonSetup.vue?raw";
9396
import codeJs from "./assets/input.js?raw";
9497
import realjsx from "./assets/real.jsx?raw";
98+
import blobtsx from "./assets/blob.tsx?raw";
9599
import codeTemplate from "./assets/PureTemplate.html?raw";
96100
import doubleRoot from "./assets/PureTemplateDoubleRoot.html?raw";
97101
import codeChicago from "./assets/Chicago.jsx?raw";
@@ -116,6 +120,7 @@ export default defineComponent({
116120
CustomLayout: markRaw(CustomLayout),
117121
chicagoRequires: { "./chicagoNeighbourhoods": all },
118122
realjsx,
123+
blobtsx,
119124
separateCode: codeSfc,
120125
doubleRoot,
121126
openExamples: false,

demo/assets/ButtonSetup.vue

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
<script lang="ts" setup>
2-
import { ref } from 'vue'
2+
import { ref, h } from 'vue'
3+
4+
const MyButton = () => {
5+
return h('button',
6+
{
7+
style: { color: 'red' },
8+
"data-cy": "my-button"
9+
},
10+
'inline component'
11+
)
12+
}
313
414
const msg = ref("Push Me")
515
</script>
616

717
<template>
818
<div class="hello">
919
<h1>Colored Text</h1>
10-
<button>{{ msg }}</button>
20+
<input v-model="msg">
21+
<div>
22+
{{ msg }}
23+
</div>
24+
<div>
25+
<MyButton/>
26+
</div>
1127
</div>
12-
</template>
13-
14-
<style>
15-
.hello {
16-
text-align: center;
17-
color: #900;
18-
}
19-
</style>
28+
</template>

demo/assets/blob.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const args = {
2+
type: "button",
3+
value: "update me",
4+
} as const;
5+
6+
type Key = keyof typeof args;
7+
8+
export default {
9+
render() {
10+
return <input {...args} />;
11+
},
12+
};

package-lock.json

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"debounce": "^1.2.1",
2424
"hash-sum": "^2.0.0",
2525
"prismjs": "^1.29.0",
26-
"vue-inbrowser-compiler-sucrase": "^4.60.0",
26+
"vue-inbrowser-compiler-sucrase": "^4.62.0",
27+
"vue-inbrowser-compiler-utils": "^4.62.1",
2728
"vue-prism-editor": "^2.0.0-alpha.2"
2829
},
2930
"devDependencies": {

0 commit comments

Comments
 (0)