Skip to content

Commit

Permalink
chore: add e2e test (#43)
Browse files Browse the repository at this point in the history
* chore: e2e snapshot commit

* chore(deps): upgrade
  • Loading branch information
sonofmagic authored Oct 9, 2023
1 parent b3f6fa6 commit f08ff27
Show file tree
Hide file tree
Showing 14 changed files with 7,964 additions and 1,662 deletions.
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "npm run e2e",
"name": "e2e",
"request": "launch",
"type": "node-terminal"
},
{
"command": "npm run prepare",
"name": "[taro-app] prepare",
Expand Down
3,277 changes: 3,277 additions & 0 deletions e2e/__snapshots__/index.test.ts.snap

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions e2e/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import prettier from 'prettier'
import automator from 'miniprogram-automator'

const projectMap = {
taroReact: {
name: 'taroReact',
root: path.resolve(__dirname, '../examples/taro-app'),
get projectPath() {
return path.resolve(this.root)
},
get cssPath() {
return path.resolve(this.projectPath, 'dist/app.wxss')
}
},
taroVue3: {
name: 'taroVue3',
root: path.resolve(__dirname, '../examples/taro-app-vue3'),
get projectPath() {
return path.resolve(this.root)
},
get cssPath() {
return path.resolve(this.projectPath, 'dist/app.wxss')
}
},
uniAppVue3: {
name: 'uniAppVue3',
root: path.resolve(__dirname, '../examples/uni-app-vue3'),
get projectPath() {
return path.resolve(this.root, 'dist/build/mp-weixin')
},
get cssPath() {
return path.resolve(this.projectPath, 'app.wxss')
}
}
}

function formatWxml(wxml: string) {
return prettier.format(wxml, {
parser: 'html',
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
endOfLine: 'lf',
trailingComma: 'none',
bracketSameLine: true,
htmlWhitespaceSensitivity: 'ignore'
})
}

function formatWxss(wxss: string) {
return prettier.format(wxss, {
parser: 'css',
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
endOfLine: 'lf',
trailingComma: 'none',
bracketSameLine: true,
htmlWhitespaceSensitivity: 'ignore'
})
}

describe('e2e', () => {
it.each(Object.values(projectMap))(
'$name snapshot',
async ({ cssPath, projectPath }) => {
const miniProgram = await automator.launch({
// cliPath: 'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat',
projectPath
})
const page = await miniProgram.reLaunch('/pages/index/index')
if (page) {
const pageEl = await page.$('page')
const wxml = await pageEl?.wxml()
if (wxml) {
let wxmlRes: string
try {
wxmlRes = await formatWxml(wxml)
} catch {
wxmlRes = wxml
}

expect(wxmlRes).toMatchSnapshot('wxml')
}

const wxss = await formatWxss(await fs.readFile(cssPath, 'utf8'))
expect(wxss).toMatchSnapshot('wxss')
await page.waitFor(3000)
}
await miniProgram.close()

// expect().toMatchSnapshot()
}
)
})
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"prepare": "pnpm run -r --parallel prepare",
"build": "pnpm run -r --parallel build"
},
"keywords": [],
"author": "",
Expand Down
Loading

0 comments on commit f08ff27

Please sign in to comment.