Skip to content

Commit

Permalink
fix: e2e test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Sep 23, 2019
1 parent b096125 commit fae5c1e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
17 changes: 17 additions & 0 deletions bin/build-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
const fs = require('fs')
const { join, resolve } = require('path')
const testRoot = resolve(__dirname, '../test')
const { ComponentParser } = require('../dist/parser/component-parser')
const { Compiler } = require('../dist/transpilers/ts2js')
const tsconfigPath = resolve(__dirname, '../test/tsconfig.json')
const ccj = new Compiler(tsconfigPath)

const parser = new ComponentParser(tsconfigPath)
let html = ''
let specTpls = ''

Expand Down Expand Up @@ -58,6 +63,18 @@ function buildFile (caseDir) {
// if it's a file, init data
if (isFile) {
switch (filename) {
case 'component.ts':
const comp = parser.parseComponent(abFilePath)
componentSource = ccj
.compileToJS(comp.getFile(abFilePath))
.replace(/(\S+)\s*=\s*require\("san"\)/, '$1 = san')
.split('\n')
.filter(x => !/exports.default/.test(x))
.filter(x => !/__esModule/.test(x))
.join('\n')
sourceFile = filename
break

case 'component.js':
componentSource = fs.readFileSync(abFilePath, 'UTF-8')
.split('\n')
Expand Down
2 changes: 1 addition & 1 deletion src/bin/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const htmlPath = resolve(__dirname, '../../test/cases', caseName, 'result.html')
const expected = readFileSync(htmlPath, 'utf8')
const [expectedData, expectedHtml] = parseHtml(expected)

// console.log(chalk.green('[COMP JS]'), measure(() => compileToJS(caseName)))
console.log(chalk.green('[COMP JS]'), measure(() => compileToJS(caseName)))
console.log(chalk.green('[COMP PHP]'), measure(() => compileToPHP(caseName)))

check(`[EXPECTED] ${caseName}`, () => expected)
Expand Down
1 change: 1 addition & 0 deletions src/php-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5585,6 +5585,7 @@ function compileComponentSource (sourceBuffer, ComponentClass, contextId) {
sourceBuffer.addRaw('if ($data) {')
Object.keys(defaultData).forEach(function (key) {
const val = stringifier.any(defaultData[key])
if (val === 'NaN') return
sourceBuffer.addRaw(`$componentCtx["data"]->${key} = isset($componentCtx["data"]->${key}) ? $componentCtx["data"]->${key} : ${val};`)
})
sourceBuffer.addRaw('}')
Expand Down
2 changes: 1 addition & 1 deletion test/cases/computed-data/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from 'san'
import { ComputedDeclarations } from '../../..'

export default class MyComponent extends Component {
computed: ComputedDeclarations = {
static computed: ComputedDeclarations = {
realTitle: function () {
return 'real' + this.data.get('title')
}
Expand Down
2 changes: 1 addition & 1 deletion test/cases/computed-dep/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from 'san'
import { ComputedDeclarations } from '../../..'

export default class MyComponent extends Component {
computed: ComputedDeclarations = {
static computed: ComputedDeclarations = {
less () {
return this.data.get('normal') - 1
},
Expand Down
3 changes: 3 additions & 0 deletions test/cases/nest-for-computed/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export default class MyComponent extends Component {

const result = {}
let start = 1

if (!cates) return result

for (let i = 0; i < cates.length; i++) {
result[cates[i]] = []
for (let j = 0; j < formLen; j++) {
Expand Down
8 changes: 4 additions & 4 deletions test/karma-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</head>
<body>
<!-- for ssr test -->
<div id="bool-attr-bindings-false"><div><!--s-data:{}--><button>button</button></div></div>
<div id="array-literal"><div><!--s-data:{"ext2":[],"ext":[]}--><ul><li>1</li><li>true</li><li>erik</li></ul></div></div>

<div id="bool-attr-bindings-false"><div><!--s-data:{}--><button>button</button></div></div>

<div id="bool-attr-bindings-true"><div><!--s-data:{"distate":true}--><button disabled>button</button></div></div>

Expand Down Expand Up @@ -52,16 +54,14 @@

<div id="computed-data"><div><!--s-data:{"title":"1","realTitle":"real1"}--><b title="real1">real1</b></div></div>

<div id="computed-dep"><div><!--s-data:{"num":10,"less":9,"more":11,"normal":10}--><a>9</a><u>10</u><b>11</b></div></div>
<div id="computed-dep"><div><!--s-data:{"less":9,"more":11,"normal":10,"num":10}--><a>9</a><u>10</u><b>11</b></div></div>

<div id="custom-tag-name"><div><!--s-data:{"text":"hello san"}--><x-p>hello san</x-p></div></div>

<div id="data-binding-camel-named"><div><!--s-data:{"title":"1","text":"one"}--><a><span title="1">one</span></a></div></div>

<div id="data-binding-no-expr"><div><!--s-data:{}--><a><u></u></a></div></div>

<div id="date-data"><div><!--s-data:{"date":"1983-09-02T16:00:00.000Z"}--><b title="1983">1983</b></div></div>

<div id="deep-slot"><div><!--s-data:{"title":"contributor","name":"errorrik","closeText":"X"}--><div><h3><b>contributor</b></h3><div><u>errorrik</u><div><a>X</a></div></div></div></div></div>

<div id="default-content-inner-data"><div><!--s-data:{"man":{"name":"errorrik","sex":1,"email":"errorrik@gmail.com"},"tip":"tip"}--><div><p>errorrik,male,errorrik@gmail.com - tip</p></div></div></div>
Expand Down

0 comments on commit fae5c1e

Please sign in to comment.