From e5a6fe5da7a68e00e0143c6f4414f7e615a684ca Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 30 May 2022 17:20:43 +0800 Subject: [PATCH] test: e2e test for composition API examples --- examples/classic/markdown/index.html | 2 +- examples/classic/svg/svg.js | 38 ++--- examples/composition/commits.html | 75 +++++++++ examples/composition/grid.html | 173 +++++++++++++++++++ examples/composition/markdown.html | 66 ++++++++ examples/composition/svg.html | 172 +++++++++++++++++++ examples/composition/todomvc.html | 241 +++++++++++++++++++++++++++ examples/composition/tree.html | 124 ++++++++++++++ package.json | 2 +- pnpm-lock.yaml | 8 +- test/e2e/commits.spec.ts | 14 +- test/e2e/e2eUtils.ts | 3 +- test/e2e/grid.spec.ts | 14 +- test/e2e/markdown.spec.ts | 14 +- test/e2e/svg.spec.ts | 22 +-- test/e2e/todomvc.spec.ts | 14 +- test/e2e/tree.spec.ts | 14 +- 17 files changed, 923 insertions(+), 73 deletions(-) create mode 100644 examples/composition/commits.html create mode 100644 examples/composition/grid.html create mode 100644 examples/composition/markdown.html create mode 100644 examples/composition/svg.html create mode 100644 examples/composition/todomvc.html create mode 100644 examples/composition/tree.html diff --git a/examples/classic/markdown/index.html b/examples/classic/markdown/index.html index 25ee26029..bc77e29c0 100644 --- a/examples/classic/markdown/index.html +++ b/examples/classic/markdown/index.html @@ -24,7 +24,7 @@ }, computed: { compiledMarkdown: function () { - return marked(this.input, { sanitize: true }) + return marked.marked(this.input) } }, methods: { diff --git a/examples/classic/svg/svg.js b/examples/classic/svg/svg.js index f4491ce30..c6df94582 100644 --- a/examples/classic/svg/svg.js +++ b/examples/classic/svg/svg.js @@ -1,5 +1,5 @@ // The raw data to observe -var stats = [ +var globalStats = [ { label: 'A', value: 100 }, { label: 'B', value: 100 }, { label: 'C', value: 100 }, @@ -16,10 +16,12 @@ Vue.component('polygraph', { // a computed property for the polygon's points points: function () { var total = this.stats.length - return this.stats.map(function (stat, i) { - var point = valueToPoint(stat.value, i, total) - return point.x + ',' + point.y - }).join(' ') + return this.stats + .map(function (stat, i) { + var point = valueToPoint(stat.value, i, total) + return point.x + ',' + point.y + }) + .join(' ') } }, components: { @@ -33,11 +35,7 @@ Vue.component('polygraph', { template: '#axis-label-template', computed: { point: function () { - return valueToPoint( - +this.stat.value + 10, - this.index, - this.total - ) + return valueToPoint(+this.stat.value + 10, this.index, this.total) } } } @@ -45,14 +43,14 @@ Vue.component('polygraph', { }) // math helper... -function valueToPoint (value, index, total) { - var x = 0 - var y = -value * 0.8 - var angle = Math.PI * 2 / total * index - var cos = Math.cos(angle) - var sin = Math.sin(angle) - var tx = x * cos - y * sin + 100 - var ty = x * sin + y * cos + 100 +function valueToPoint(value, index, total) { + var x = 0 + var y = -value * 0.8 + var angle = ((Math.PI * 2) / total) * index + var cos = Math.cos(angle) + var sin = Math.sin(angle) + var tx = x * cos - y * sin + 100 + var ty = x * sin + y * cos + 100 return { x: tx, y: ty @@ -64,7 +62,7 @@ new Vue({ el: '#demo', data: { newLabel: '', - stats: stats + stats: globalStats }, methods: { add: function (e) { @@ -80,7 +78,7 @@ new Vue({ if (this.stats.length > 3) { this.stats.splice(this.stats.indexOf(stat), 1) } else { - alert('Can\'t delete more!') + alert("Can't delete more!") } } } diff --git a/examples/composition/commits.html b/examples/composition/commits.html new file mode 100644 index 000000000..3c16a3f7b --- /dev/null +++ b/examples/composition/commits.html @@ -0,0 +1,75 @@ + + +
+

Latest Vue.js Commits

+ +

vuejs/vue@{{ currentBranch }}

+ +
+ + + + diff --git a/examples/composition/grid.html b/examples/composition/grid.html new file mode 100644 index 000000000..090d3d7db --- /dev/null +++ b/examples/composition/grid.html @@ -0,0 +1,173 @@ + + + + + + + + +
+ + + +
+ + + + diff --git a/examples/composition/markdown.html b/examples/composition/markdown.html new file mode 100644 index 000000000..d3387de4a --- /dev/null +++ b/examples/composition/markdown.html @@ -0,0 +1,66 @@ + + + + +
+ +
+
+ + + + diff --git a/examples/composition/svg.html b/examples/composition/svg.html new file mode 100644 index 000000000..2b4d5e0c3 --- /dev/null +++ b/examples/composition/svg.html @@ -0,0 +1,172 @@ + + + + + + + + + +
+ + + + + +
+ + + {{stat.value}} + +
+
+ + +
+
{{ stats }}
+
+ + + + diff --git a/examples/composition/todomvc.html b/examples/composition/todomvc.html new file mode 100644 index 000000000..ac806bc83 --- /dev/null +++ b/examples/composition/todomvc.html @@ -0,0 +1,241 @@ + + + +
+
+
+

todos

+ +
+
+ + +
    +
  • +
    + + + +
    + +
  • +
+
+
+ + {{ state.remaining }} + {{ state.remainingText }} + + + + +
+
+
+ + diff --git a/examples/composition/tree.html b/examples/composition/tree.html new file mode 100644 index 000000000..c39fe3987 --- /dev/null +++ b/examples/composition/tree.html @@ -0,0 +1,124 @@ + + + + + + + +

(You can double click on an item to turn it into a folder.)

+ + + + + + + diff --git a/package.json b/package.json index a631ac6d4..e1ab5d5da 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "lodash.template": "^4.4.0", "lodash.uniq": "^4.5.0", "lru-cache": "^7.8.1", - "marked": "^3.0.8", + "marked": "^4.0.6", "memory-fs": "^0.5.0", "prettier": "^2.6.2", "puppeteer": "^14.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0f328bff..a03e974e3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,7 +32,7 @@ specifiers: lodash.template: ^4.4.0 lodash.uniq: ^4.5.0 lru-cache: ^7.8.1 - marked: ^3.0.8 + marked: ^4.0.6 memory-fs: ^0.5.0 prettier: ^2.6.2 puppeteer: ^14.1.1 @@ -83,7 +83,7 @@ devDependencies: lodash.template: 4.5.0 lodash.uniq: 4.5.0 lru-cache: 7.10.1 - marked: 3.0.8 + marked: 4.0.16 memory-fs: 0.5.0 prettier: 2.6.2 puppeteer: 14.1.1 @@ -3747,8 +3747,8 @@ packages: object-visit: 1.0.1 dev: true - /marked/3.0.8: - resolution: {integrity: sha512-0gVrAjo5m0VZSJb4rpL59K1unJAMb/hm8HRXqasD8VeC8m91ytDPMritgFSlKonfdt+rRYYpP/JfLxgIX8yoSw==} + /marked/4.0.16: + resolution: {integrity: sha512-wahonIQ5Jnyatt2fn8KqF/nIqZM8mh3oRu2+l5EANGMhu6RFjiSG52QNE2eWzFMI94HqYSgN184NurgNG6CztA==} engines: {node: '>= 12'} hasBin: true dev: true diff --git a/test/e2e/commits.spec.ts b/test/e2e/commits.spec.ts index 73e94667f..28796fe7c 100644 --- a/test/e2e/commits.spec.ts +++ b/test/e2e/commits.spec.ts @@ -52,11 +52,11 @@ describe('e2e: commits', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testCommits('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testCommits('composition') + }, + E2E_TIMEOUT + ) }) diff --git a/test/e2e/e2eUtils.ts b/test/e2e/e2eUtils.ts index d9224e62e..b991cbd29 100644 --- a/test/e2e/e2eUtils.ts +++ b/test/e2e/e2eUtils.ts @@ -5,9 +5,10 @@ export function getExampleUrl( name: string, apiType: 'classic' | 'composition' ) { + const file = apiType === 'composition' ? `${name}.html` : `${name}/index.html` return `file://${path.resolve( __dirname, - `../../examples/${apiType}/${name}/index.html` + `../../examples/${apiType}/${file}` )}` } diff --git a/test/e2e/grid.spec.ts b/test/e2e/grid.spec.ts index 9648872df..937a5bbb2 100644 --- a/test/e2e/grid.spec.ts +++ b/test/e2e/grid.spec.ts @@ -105,11 +105,11 @@ describe('e2e: grid', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testGrid('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testGrid('composition') + }, + E2E_TIMEOUT + ) }) diff --git a/test/e2e/markdown.spec.ts b/test/e2e/markdown.spec.ts index cd1d64f5d..67b7244af 100644 --- a/test/e2e/markdown.spec.ts +++ b/test/e2e/markdown.spec.ts @@ -36,11 +36,11 @@ describe('e2e: markdown', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testMarkdown('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testMarkdown('composition') + }, + E2E_TIMEOUT + ) }) diff --git a/test/e2e/svg.spec.ts b/test/e2e/svg.spec.ts index e8584e87d..5032ca4c6 100644 --- a/test/e2e/svg.spec.ts +++ b/test/e2e/svg.spec.ts @@ -1,6 +1,6 @@ import { setupPuppeteer, getExampleUrl, E2E_TIMEOUT } from './e2eUtils' -declare const stats: { +declare const globalStats: { label: string value: number }[] @@ -22,7 +22,7 @@ describe('e2e: svg', () => { expect( await page().evaluate( total => { - const points = stats + const points = globalStats .map((stat, i) => { const point = valueToPoint(stat.value, i, total) return point.x + ',' + point.y @@ -41,7 +41,7 @@ describe('e2e: svg', () => { async function assertLabels(total: number) { const positions = await page().evaluate( total => { - return stats.map((stat, i) => { + return globalStats.map((stat, i) => { const point = valueToPoint(+stat.value + 10, i, total) return [point.x, point.y] }) @@ -60,7 +60,7 @@ describe('e2e: svg', () => { // assert each value of stats is correct async function assertStats(expected: number[]) { const statsValue = await page().evaluate(() => { - return stats.map(stat => +stat.value) + return globalStats.map(stat => +stat.value) }) expect(statsValue).toEqual(expected) } @@ -141,11 +141,11 @@ describe('e2e: svg', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testSvg('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testSvg('composition') + }, + E2E_TIMEOUT + ) }) diff --git a/test/e2e/todomvc.spec.ts b/test/e2e/todomvc.spec.ts index b73b3e214..f1de97e63 100644 --- a/test/e2e/todomvc.spec.ts +++ b/test/e2e/todomvc.spec.ts @@ -172,11 +172,11 @@ describe('e2e: todomvc', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testTodomvc('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testTodomvc('composition') + }, + E2E_TIMEOUT + ) }) diff --git a/test/e2e/tree.spec.ts b/test/e2e/tree.spec.ts index 360374100..970aaa5ea 100644 --- a/test/e2e/tree.spec.ts +++ b/test/e2e/tree.spec.ts @@ -98,11 +98,11 @@ describe('e2e: tree', () => { E2E_TIMEOUT ) - // test( - // 'composition', - // async () => { - // await testTree('composition') - // }, - // E2E_TIMEOUT - // ) + test( + 'composition', + async () => { + await testTree('composition') + }, + E2E_TIMEOUT + ) })