Skip to content

Commit af6411d

Browse files
authored
feat: setup testing for CTA (#1615)
* feat: setup testing for CTA * install with yarn * build before test * add yarn to npm runs for install / test start * add dev mode to link cli.js and api locally * remove fixtures * run tests serially * cli.js build-release avoids webpack error * assert on package.json contents as first check * run tauri build and split out custom asserts * add changefile * shorten workflow name * too short * exclude npm@6 on node@16 * increase timeout, tauri build takes a bit of time * only assert that the tauri script exists
1 parent ddcd923 commit af6411d

9 files changed

Lines changed: 331 additions & 29 deletions

File tree

.changes/cta-testing-suite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": patch
3+
---
4+
5+
We setup an e2e type test suite for CTA. It is mostly an internal change, but should help with stability moving forward.

.github/workflows/test-cta.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
# SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: MIT
4+
5+
name: test create-tauri-app
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
branch:
11+
default: "dev"
12+
pull_request:
13+
paths:
14+
- "tooling/create-tauri-app/**"
15+
16+
env:
17+
RUST_BACKTRACE: 1
18+
19+
jobs:
20+
create-recipe-with-npm:
21+
name: "node@${{ matrix.node }} + npm@${{ matrix.manager }}: ${{ matrix.recipe }}"
22+
runs-on: ubuntu-latest
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
node: ["14", "16"]
28+
manager: ["6", "7"]
29+
recipe: ["vanillajs", "reactjs", "reactts", "vite", "vuecli"]
30+
exclude:
31+
- node: "16"
32+
manager: "6"
33+
34+
steps:
35+
- uses: actions/checkout@v2
36+
with:
37+
ref: ${{ github.head_ref || github.event.inputs.branch }}
38+
- name: install stable
39+
uses: actions-rs/toolchain@v1
40+
with:
41+
toolchain: stable
42+
- uses: volta-cli/action@v1
43+
with:
44+
node-version: ${{ matrix.node }}
45+
npm-version: ${{ matrix.manager }}
46+
yarn-version: 1.22.5
47+
- name: install webkit2gtk (ubuntu only)
48+
if: matrix.platform == 'ubuntu-latest'
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y webkit2gtk-4.0
52+
- run: yarn
53+
working-directory: tooling/create-tauri-app
54+
- run: yarn build
55+
working-directory: tooling/create-tauri-app
56+
- run: yarn test
57+
working-directory: tooling/create-tauri-app
58+
env:
59+
TAURI_RECIPE: ${{ matrix.recipe }}
60+
TAURI_RUN_MANAGER: "npm"
61+
62+
create-recipe-with-yarn:
63+
name: "node@${{ matrix.node }} + yarn@1: ${{ matrix.recipe }}"
64+
runs-on: ubuntu-latest
65+
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
node: ["14", "16"]
70+
recipe: ["vanillajs", "reactjs", "reactts", "vite", "vuecli"]
71+
72+
steps:
73+
- uses: actions/checkout@v2
74+
with:
75+
ref: ${{ github.head_ref || github.event.inputs.branch }}
76+
- name: install stable
77+
uses: actions-rs/toolchain@v1
78+
with:
79+
toolchain: stable
80+
- uses: volta-cli/action@v1
81+
with:
82+
node-version: ${{ matrix.node }}
83+
yarn-version: 1.22.5
84+
- name: install webkit2gtk (ubuntu only)
85+
if: matrix.platform == 'ubuntu-latest'
86+
run: |
87+
sudo apt-get update
88+
sudo apt-get install -y webkit2gtk-4.0
89+
- run: yarn
90+
working-directory: tooling/create-tauri-app
91+
- run: yarn build
92+
working-directory: tooling/create-tauri-app
93+
- run: yarn test
94+
working-directory: tooling/create-tauri-app
95+
env:
96+
TAURI_RECIPE: ${{ matrix.recipe }}
97+
TAURI_RUN_MANAGER: "yarn"

tooling/create-tauri-app/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
},
88

99
parser: '@typescript-eslint/parser',
10-
10+
ignorePatterns: ['.eslintrc.js', 'jest.config.js', 'test/**/*'],
1111
extends: [
1212
'standard-with-typescript',
1313
'plugin:@typescript-eslint/recommended-requiring-type-checking',

tooling/create-tauri-app/bin/create-tauri-app.js

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
* @property {boolean} log
3030
* @property {boolean} d
3131
* @property {boolean} directory
32+
* @property {boolean} dev
3233
* @property {string} r
3334
* @property {string} recipe
3435
*/
@@ -41,15 +42,15 @@ const createTauriApp = async (cliArgs) => {
4142
l: 'log',
4243
m: 'manager',
4344
d: 'directory',
44-
b: 'binary',
45+
dev: 'dev',
4546
t: 'tauri-path',
4647
A: 'app-name',
4748
W: 'window-title',
4849
D: 'dist-dir',
4950
P: 'dev-path',
5051
r: 'recipe'
5152
},
52-
boolean: ['h', 'l', 'ci']
53+
boolean: ['h', 'l', 'ci', 'dev']
5354
})
5455

5556
if (argv.help) {
@@ -62,13 +63,9 @@ const createTauriApp = async (cliArgs) => {
6263
return false // do this for node consumers and tests
6364
}
6465

65-
if (argv.ci) {
66-
return runInit(argv)
67-
} else {
68-
return getOptionsInteractive(argv).then((responses) =>
69-
runInit(argv, responses)
70-
)
71-
}
66+
return getOptionsInteractive(argv, !argv.ci).then((responses) =>
67+
runInit(argv, responses)
68+
)
7269
}
7370

7471
function printUsage() {
@@ -95,38 +92,46 @@ function printUsage() {
9592
`)
9693
}
9794

98-
const getOptionsInteractive = (argv) => {
99-
let defaultAppName = argv.A || 'tauri-app'
95+
const getOptionsInteractive = (argv, ask) => {
96+
const defaults = {
97+
appName: argv.A || 'tauri-app',
98+
tauri: { window: { title: 'Tauri App' } },
99+
recipeName: argv.r || 'vanillajs'
100+
}
100101

101102
return inquirer
102103
.prompt([
103104
{
104105
type: 'input',
105106
name: 'appName',
106107
message: 'What is your app name?',
107-
default: defaultAppName,
108-
when: !argv.A
108+
default: defaults.appName,
109+
when: ask && !argv.A
109110
},
110111
{
111112
type: 'input',
112113
name: 'tauri.window.title',
113114
message: 'What should the window title be?',
114-
default: 'Tauri App',
115-
when: () => !argv.W
115+
default: defaults.tauri.window.title,
116+
when: ask && !argv.W
116117
},
117118
{
118119
type: 'list',
119120
name: 'recipeName',
120121
message: 'Would you like to add a UI recipe?',
121122
choices: recipeDescriptiveNames,
122-
default: 'No recipe',
123-
when: () => !argv.r
123+
default: defaults.recipeName,
124+
when: ask && !argv.r
124125
}
125126
])
127+
.then((answers) => ({
128+
...defaults,
129+
...answers
130+
}))
126131
.catch((error) => {
127132
if (error.isTtyError) {
128133
// Prompt couldn't be rendered in the current environment
129-
console.log(
134+
console.warn(
130135
'It appears your terminal does not support interactive prompts. Using default values.'
131136
)
132137
runInit()
@@ -150,10 +155,10 @@ async function runInit(argv, config = {}) {
150155

151156
let recipe
152157

153-
if (recipeName !== undefined) {
154-
recipe = recipeByDescriptiveName(recipeName)
155-
} else if (argv.r) {
158+
if (argv.r) {
156159
recipe = recipeByShortName(argv.r)
160+
} else if (recipeName !== undefined) {
161+
recipe = recipeByDescriptiveName(recipeName)
157162
}
158163

159164
let buildConfig = {
@@ -201,10 +206,21 @@ async function runInit(argv, config = {}) {
201206
// Vue CLI plugin automatically runs these
202207
if (recipe.shortName !== 'vuecli') {
203208
console.log('===== installing any additional needed deps =====')
209+
if (argv.dev) {
210+
await shell('yarn', ['link', '@tauri-apps/cli'], {
211+
cwd: appDirectory
212+
})
213+
await shell('yarn', ['link', '@tauri-apps/api'], {
214+
cwd: appDirectory
215+
})
216+
}
217+
204218
await install({
205219
appDir: appDirectory,
206220
dependencies: recipe.extraNpmDependencies,
207-
devDependencies: ['@tauri-apps/cli', ...recipe.extraNpmDevDependencies],
221+
devDependencies: argv.dev
222+
? [...recipe.extraNpmDevDependencies]
223+
: ['@tauri-apps/cli'].concat(recipe.extraNpmDevDependencies),
208224
packageManager
209225
})
210226

@@ -216,7 +232,7 @@ async function runInit(argv, config = {}) {
216232
packageManager === 'npm' && !argv.b
217233
? ['run', 'tauri', '--', 'init']
218234
: ['tauri', 'init']
219-
await shell(binary, [...runTauriArgs, ...initArgs], {
235+
await shell(binary, [...runTauriArgs, ...initArgs, '--ci'], {
220236
cwd: appDirectory
221237
})
222238
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
module.exports = {
6+
preset: 'ts-jest',
7+
testEnvironment: 'node',
8+
modulePathIgnorePatterns: ['__fixtures__'],
9+
testMatch: ['<rootDir>/test/**/*.spec.ts'],
10+
moduleFileExtensions: ['ts', 'js', 'json'],
11+
globals: {
12+
'ts-jest': {
13+
tsconfig: 'tsconfig.json'
14+
}
15+
}
16+
}

tooling/create-tauri-app/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"lint-fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
3030
"lint:lockfile": "lockfile-lint --path yarn.lock --type yarn --validate-https --allowed-hosts npm yarn",
3131
"format": "prettier --write --end-of-line=auto \"./**/*.{js,jsx,ts,tsx,html,css,json}\" --ignore-path .gitignore",
32-
"format:check": "prettier --check --end-of-line=auto \"./**/*.{js,jsx,ts,tsx,html,css,json}\" --ignore-path .gitignore"
32+
"format:check": "prettier --check --end-of-line=auto \"./**/*.{js,jsx,ts,tsx,html,css,json}\" --ignore-path .gitignore",
33+
"test": "jest --runInBand"
3334
},
3435
"dependencies": {
3536
"execa": "^5.0.0",
@@ -41,11 +42,12 @@
4142
"@rollup/plugin-commonjs": "18.0.0",
4243
"@rollup/plugin-node-resolve": "11.2.1",
4344
"@rollup/plugin-typescript": "8.2.1",
44-
"@typescript-eslint/eslint-plugin": "4.22.0",
45-
"@typescript-eslint/parser": "4.22.0",
4645
"@types/cross-spawn": "6.0.2",
4746
"@types/inquirer": "7.3.1",
47+
"@types/jest": "^26.0.22",
4848
"@types/semver": "7.3.4",
49+
"@typescript-eslint/eslint-plugin": "4.22.0",
50+
"@typescript-eslint/parser": "4.22.0",
4951
"eslint": "7.24.0",
5052
"eslint-config-prettier": "8.2.0",
5153
"eslint-config-standard-with-typescript": "20.0.0",
@@ -54,8 +56,11 @@
5456
"eslint-plugin-node": "11.1.0",
5557
"eslint-plugin-promise": "5.1.0",
5658
"eslint-plugin-security": "1.4.0",
59+
"fixturez": "^1.1.0",
60+
"jest": "^26.6.3",
5761
"prettier": "2.2.1",
5862
"rollup": "2.45.1",
63+
"ts-jest": "^26.5.5",
5964
"tslib": "2.2.0",
6065
"typescript": "4.2.4"
6166
}

0 commit comments

Comments
 (0)