feat/web-view (#52)

* feat(web-view): revert to now well-maintained upstream web-view [WIP]

* feat(tests): add jest testing, first test

* feat(lint): install, config and fix
This commit is contained in:
nothingismagick 2019-11-16 19:51:46 +01:00 committed by GitHub
parent 1ee1933da5
commit 5ec8e2f2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 4882 additions and 162 deletions

1
.env.jest Normal file
View File

@ -0,0 +1 @@
NODE_ENV=test

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
/src-tauri

23
.eslintrc.js Normal file
View File

@ -0,0 +1,23 @@
module.exports = {
env: {
node: true,
jest: true
},
extends: ["standard"],
plugins: [],
globals: {
__statics: true,
process: true
},
// add your custom rules here
rules: {
// allow console.log during development only
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
// allow debugger during development only
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
}
}

3
.gitignore vendored
View File

@ -59,3 +59,6 @@ typings/
debug.log
package-lock.json
.vscode/settings.json
src-tauri

View File

@ -6,3 +6,5 @@ node_modules
.github
.idea
SECURITY.md
src-tauri

35
jest.config.js Normal file
View File

@ -0,0 +1,35 @@
module.exports = {
globals: {
__DEV__: true
},
setupFilesAfterEnv: ['<rootDir>/test/jest/jest.setup.js'],
// noStackTrace: true,
// bail: true,
// cache: false,
// verbose: true,
// watch: true,
collectCoverage: true,
coverageDirectory: '<rootDir>/test/jest/coverage',
collectCoverageFrom: [
'<rootDir>/mode/**/*.js',
],
coverageReporters: ['json-summary', 'text', 'lcov'],
coverageThreshold: {
global: {
// branches: 50,
// functions: 50,
// lines: 50,
// statements: 50
}
},
testMatch: [
'<rootDir>/test/jest/__tests__/**/*.spec.js',
'<rootDir>/test/jest/__tests__/**/*.test.js'
],
moduleFileExtensions: ['js', 'json'],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/$1',
'^mode/(.*)$': '<rootDir>/mode/$1'
},
transform: {}
}

View File

@ -6,29 +6,30 @@ license = "MIT"
edition = "2018"
[dependencies]
tauri-ui = { path = "../../bindings/rust" }
serde_json = "1.0.39"
# tauri-ui = { path = "../../bindings/rust" }
web-view = "0.5.3"
serde_json = "1.0.41"
serde = "1.0"
serde_derive = "1.0"
dirs = "1.0"
ignore = "0.4.7"
phf = "0.7.21"
dirs = "2.0.2"
ignore = "0.4.10"
phf = "0.8.0"
threadpool = "1.7"
rand = "0.7"
reqwest = "0.9"
pbr = "1"
zip = "0.5.0"
zip = "0.5.3"
tempdir = "0.3"
semver = "0.9"
tempfile = "3"
either = "1.5.0"
either = "1.5.3"
tar = "0.4"
flate2 = "1"
hyper-old-types = "0.11.0"
sysinfo = "0.9"
webbrowser = "0.5.1"
uuid = { version = "0.7", features = ["v4"] }
lazy_static = "1.3.0"
webbrowser = "0.5.2"
uuid = { version = "0.8.1", features = ["v4"] }
lazy_static = "1.4.0"
includedir = "0.5.0"
tiny_http = "0.6"
clap = {version = "2.33", features = ["yaml"]}
@ -37,6 +38,7 @@ clap = {version = "2.33", features = ["yaml"]}
includedir_codegen = "0.5.0"
[features]
# edge = ["webview-sys/edge"]
dev = []
embedded-server = []
all-api = []

View File

@ -1,6 +1,6 @@
mod cmd;
use tauri_ui::WebView;
use web_view::WebView;
#[allow(unused_variables)]
pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
@ -23,21 +23,21 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
}}).then(function () {{
const listeners = (window['{listeners}'] && window['{listeners}'][payload.type]) || []
if (!ignoreQueue && listeners.length === 0) {{
window['{queue}'].push({{
if (!ignoreQueue && listeners.length === 0) {{
window['{queue}'].push({{
payload: payload,
salt: salt
}})
}}
for (let i = listeners.length - 1; i >= 0; i--) {{
for (let i = listeners.length - 1; i >= 0; i--) {{
const listener = listeners[i]
if (listener.once)
listeners.splice(i, 1)
listener.handler(payload)
}}
}})
}}",
}}",
fn = crate::event::emit_function_name(),
listeners = crate::event::event_listeners_object_name(),
queue = crate::event::event_queue_object_name()
@ -125,7 +125,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
webview
.eval(&format!(
"
if (window['{listeners}'] === void 0) {{
if (window['{listeners}'] === void 0) {{
window['{listeners}'] = {{}}
}}
if (window['{listeners}']['{evt}'] === void 0) {{
@ -136,7 +136,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
once: {once_flag}
}});
for (let i = 0; i < window['{queue}'].length; i++) {{
for (let i = 0; i < window['{queue}'].length; i++) {{
const e = window['{queue}'][i];
window['{emit}'](e.payload, e.salt, true)
}}

View File

@ -1,5 +1,5 @@
mod runner;
use tauri_ui::WebView;
use web_view::WebView;
//type FnMut(&mut InvokeHandler<WebView<'_, ()>>, &str) = FnMut(&mut FnMut(&mut InvokeHandler<WebView<'_, ()>>, &str)<WebView<'_, ()>>, &str);

View File

@ -41,7 +41,7 @@ pub(crate) fn run(application: &mut crate::App) {
);
let matches = app.get_matches();
content = tauri_ui::Content::Url(matches.value_of("url").unwrap().to_owned());
content = web_view::Content::Url(matches.value_of("url").unwrap().to_owned());
debug = true;
}
@ -51,7 +51,7 @@ pub(crate) fn run(application: &mut crate::App) {
#[cfg(not(feature = "embedded-server"))]
{
content =
tauri_ui::Content::Html(include_str!(concat!(env!("TAURI_DIST_DIR"), "/index.html")));
web_view::Content::Html(include_str!(concat!(env!("TAURI_DIST_DIR"), "/index.html")));
}
#[cfg(feature = "embedded-server")]
{
@ -81,14 +81,14 @@ pub(crate) fn run(application: &mut crate::App) {
if !server_url.starts_with("http") {
server_url = format!("http://{}", server_url);
}
content = tauri_ui::Content::Url(server_url.clone());
content = web_view::Content::Url(server_url.clone());
} else {
panic!(format!("Port {} is not valid or not open", port));
}
}
}
let webview = tauri_ui::builder()
let webview = web_view::builder()
.title(&config.window.title)
.size(config.window.width, config.window.height)
.resizable(config.window.resizable)

View File

@ -1,4 +1,4 @@
use tauri_ui::WebView;
use web_view::WebView;
use std::process::{Child, Command, Stdio};

View File

@ -1,7 +1,7 @@
use std::boxed::Box;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tauri_ui::Handle;
use web_view::Handle;
struct EventHandler {
on_event: Box<dyn FnOnce(String)>,

View File

@ -1,4 +1,4 @@
use tauri_ui::WebView;
use web_view::WebView;
use crate::dir;
use crate::execute_promise;

View File

@ -7,6 +7,8 @@ mod macros;
#[macro_use]
extern crate lazy_static;
extern crate web_view;
pub mod api;
mod app;
pub mod command;
@ -27,7 +29,7 @@ pub mod updater;
pub mod version;
pub use app::*;
use tauri_ui::WebView;
use web_view::*;
use threadpool::ThreadPool;

View File

@ -1,5 +1,5 @@
use std::sync::Mutex;
use tauri_ui::WebView;
use web_view::WebView;
use uuid::Uuid;
struct Salt {

View File

@ -89,7 +89,7 @@ export default class Tauri {
* @param {Boolean} once
*/
<% } %>
static addEventListener(evt, handler, once = false) {
static addEventListener (evt, handler, once = false) {
this.invoke({
cmd: 'addEventListener',
evt,

View File

@ -21,14 +21,14 @@ if (argv.help) {
process.exit(0)
}
const { tauriDir } = require('../helpers/app-paths'),
Runner = require('../runner'),
tauri = new Runner({modeDir: tauriDir}),
tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: argv.debug
}
})
const { tauriDir } = require('../helpers/app-paths')
const Runner = require('../runner')
const tauri = new Runner({ modeDir: tauriDir })
const tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: argv.debug
}
})
require('../generator').generate(tauriConfig.tauri)
require('../entry').generate(tauriDir, tauriConfig)

View File

@ -20,14 +20,14 @@ if (argv.help) {
process.exit(0)
}
const { tauriDir } = require('../helpers/app-paths'),
Runner = require('../runner'),
tauri = new Runner(),
tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: true
}
})
const { tauriDir } = require('../helpers/app-paths')
const Runner = require('../runner')
const tauri = new Runner()
const tauriConfig = require('../helpers/tauri-config')({
ctx: {
debug: true
}
})
require('../generator').generate(tauriConfig.tauri)
require('../entry').generate(tauriDir, tauriConfig)

0
mode/bin/tauri-help.js Normal file
View File

View File

@ -1,9 +1,9 @@
const
parseArgs = require('minimist'),
appPaths = require('../helpers/app-paths'),
logger = require('../helpers/logger'),
log = logger('app:tauri'),
warn = logger('app:tauri (init)', 'red')
parseArgs = require('minimist')
const appPaths = require('../helpers/app-paths')
const logger = require('../helpers/logger')
const log = logger('app:tauri')
const warn = logger('app:tauri (init)', 'red')
/**
* @type {object}
@ -15,34 +15,36 @@ const
* @property {boolean} log
*/
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
f: 'force',
l: 'log'
},
boolean: ['h', 'l']
alias: {
h: 'help',
f: 'force',
l: 'log',
d: 'directory'
},
boolean: ['h', 'l']
})
if (argv.help) {
console.log(`
console.log(`
Description
Inits the Tauri template. If Tauri cannot find the tauri.conf.js
it will create one.
Usage
$ tauri init
Options
--help, -h Displays this message
--force, -f Force init to overwrite [conf|template|all]
--log, l Logging [boolean]
`)
process.exit(0)
--help, -h Displays this message
--force, -f Force init to overwrite [conf|template|all]
--log, l Logging [boolean]
--directory, d Set target directory for init
`)
process.exit(0)
}
const { inject } = require('../template')
const target = appPaths.tauriDir
if (inject(target, 'all', argv.f, argv.l)) {
if (inject(target, 'all', argv.f, argv.l, argv.d)) {
log('tauri init successful')
} else {
warn('tauri init unsuccessful')

View File

@ -3,20 +3,30 @@
const cmds = ['init', 'dev', 'build', 'help']
const cmd = process.argv[2]
if (!cmd || cmd === '-h' || cmd === '--help' || cmd === 'help') {
console.log(`
Description
This is the Tauri CLI.
Usage
$ tauri ${cmds.join('|')}
Options
--help, -h Displays this message
`)
process.exit(0)
}
if (cmds.includes(cmd)) {
process.argv.splice(2, 1)
require(`./tauri-${cmd}`)
} else {
console.log(`Invalid command ${cmd}. Use one of ${cmds.join(',')}.`)
const tauri = function (command) {
if (!command || command === '-h' || command === '--help' || command === 'help') {
console.log(`
Description
This is the Tauri CLI.
Usage
$ tauri ${cmds.join('|')}
Options
--help, -h Displays this message
`)
process.exit(0)
return false// do this for node consumers and tests
}
if (cmds.includes(command)) {
if (process.argv) {
process.argv.splice(2, 1)
}
console.log(`[tauri]: running ${command}`)
require(`./tauri-${command}`)
} else {
console.log(`Invalid command ${command}. Use one of ${cmds.join(',')}.`)
}
}
module.exports = { tauri }
tauri(cmd)

View File

@ -1,6 +1,6 @@
const compileTemplate = require('lodash.template'),
{ readFileSync, writeFileSync, ensureDir } = require('fs-extra'),
path = require('path')
const compileTemplate = require('lodash.template')
const { readFileSync, writeFileSync, ensureDir } = require('fs-extra')
const path = require('path')
module.exports.generate = (outDir, cfg) => {
const apiTemplate = readFileSync(path.resolve(__dirname, '../lib/tauri.js'), 'utf-8')

View File

@ -1,12 +1,12 @@
const
path = require('path'),
{ writeFileSync } = require('fs-extra'),
{ tauriDir } = require('./helpers/app-paths')
path = require('path')
const { writeFileSync } = require('fs-extra')
const { tauriDir } = require('./helpers/app-paths')
module.exports.generate = tauriConfig => {
const
{ bundle, ...cfg } = tauriConfig,
outDir = tauriDir
{ bundle, ...cfg } = tauriConfig
const outDir = tauriDir
writeFileSync(path.join(outDir, 'config.json'), JSON.stringify(cfg))
writeFileSync(path.join(outDir, 'bundle.json'), JSON.stringify(bundle))
}

View File

@ -1,12 +1,12 @@
const
{ existsSync } = require('fs'),
{ resolve, join, normalize, sep } = require('path')
{ existsSync } = require('fs')
const { resolve, join, normalize, sep } = require('path')
/**
*
* @returns {{length}|*}
*/
function getAppDir() {
function getAppDir () {
let dir = process.cwd()
let count = 0
@ -24,8 +24,8 @@ function getAppDir() {
return process.cwd()
}
const appDir = getAppDir(),
tauriDir = resolve(appDir, 'src-tauri')
const appDir = getAppDir()
const tauriDir = resolve(appDir, 'src-tauri')
module.exports = {
appDir,

View File

@ -1,14 +1,14 @@
const
ms = require('ms'),
chalk = require('chalk')
ms = require('ms')
const chalk = require('chalk')
let prevTime
module.exports = function (banner, color = 'green') {
return function (msg) {
const
curr = +new Date(),
diff = curr - (prevTime || curr)
curr = +new Date()
const diff = curr - (prevTime || curr)
prevTime = curr

View File

@ -1,8 +1,8 @@
const
logger = require('./logger'),
log = logger('app:spawn'),
warn = logger('app:spawn', 'red'),
crossSpawn = require('cross-spawn')
logger = require('./logger')
const log = logger('app:spawn')
const warn = logger('app:spawn', 'red')
const crossSpawn = require('cross-spawn')
/*
Returns pid, takes onClose

View File

@ -1,5 +1,5 @@
const appPaths = require('./app-paths'),
merge = require('webpack-merge')
const appPaths = require('./app-paths')
const merge = require('webpack-merge')
module.exports = cfg => {
const tauriConf = require(appPaths.resolve.app('tauri.conf.js'))(cfg.ctx)

View File

@ -1,18 +1,21 @@
const
chokidar = require('chokidar'),
debounce = require('lodash.debounce'),
path = require('path'),
{ readFileSync, writeFileSync } = require('fs-extra')
chokidar = require('chokidar')
const debounce = require('lodash.debounce')
const path = require('path')
const { readFileSync, writeFileSync } = require('fs-extra')
const
{ spawn } = require('./helpers/spawn'),
log = require('./helpers/logger')('app:tauri'),
onShutdown = require('./helpers/on-shutdown'),
generator = require('./generator'),
{ appDir, tauriDir } = require('./helpers/app-paths')
{ spawn } = require('./helpers/spawn')
const onShutdown = require('./helpers/on-shutdown')
const generator = require('./generator')
const { appDir, tauriDir } = require('./helpers/app-paths')
const logger = require('./helpers/logger')
const log = logger('app:tauri', 'green')
const warn = log('app:tauri (template)', 'red')
class Runner {
constructor() {
constructor () {
this.pid = 0
this.tauriWatcher = null
onShutdown(() => {
@ -20,7 +23,7 @@ class Runner {
})
}
async run(cfg) {
async run (cfg) {
process.env.TAURI_DIST_DIR = cfg.build.distDir
process.env.TAURI_CONFIG_DIR = tauriDir
const url = cfg.build.APP_URL
@ -72,7 +75,7 @@ class Runner {
return startDevTauri()
}
async build(cfg) {
async build (cfg) {
process.env.TAURI_DIST_DIR = cfg.build.distDir
process.env.TAURI_CONFIG_DIR = tauriDir
@ -107,14 +110,14 @@ class Runner {
}
}
stop() {
stop () {
return new Promise((resolve, reject) => {
this.tauriWatcher && this.tauriWatcher.close()
this.__stopCargo().then(resolve)
})
}
__runCargoCommand({
__runCargoCommand ({
cargoArgs,
extraArgs
}) {
@ -122,16 +125,16 @@ class Runner {
this.pid = spawn(
'cargo',
extraArgs ?
cargoArgs.concat(['--']).concat(extraArgs) :
cargoArgs,
extraArgs
? cargoArgs.concat(['--']).concat(extraArgs)
: cargoArgs,
tauriDir,
code => {
if (code) {
warn()
warn(`⚠️ [FAIL] Cargo CLI has failed`)
warn('⚠️ [FAIL] Cargo CLI has failed')
warn()
process.exit(1)
}
@ -152,7 +155,7 @@ class Runner {
})
}
__stopCargo() {
__stopCargo () {
const pid = this.pid
if (!pid) {
@ -168,11 +171,11 @@ class Runner {
})
}
__manipulateToml(callback) {
const toml = require('@iarna/toml'),
tomlPath = path.join(tauriDir, 'Cargo.toml'),
tomlFile = readFileSync(tomlPath),
tomlContents = toml.parse(tomlFile)
__manipulateToml (callback) {
const toml = require('@iarna/toml')
const tomlPath = path.join(tauriDir, 'Cargo.toml')
const tomlFile = readFileSync(tomlPath)
const tomlContents = toml.parse(tomlFile)
callback(tomlContents)
@ -180,7 +183,7 @@ class Runner {
writeFileSync(tomlPath, output)
}
__whitelistApi(cfg, tomlContents) {
__whitelistApi (cfg, tomlContents) {
if (!tomlContents.dependencies.tauri.features) {
tomlContents.dependencies.tauri.features = []
}

View File

@ -1,10 +1,10 @@
const { copySync, renameSync, existsSync, mkdirSync, removeSync } = require('fs-extra'),
{ resolve, join, normalize } = require('path'),
logger = require('./helpers/logger'),
log = logger('app:tauri', 'green'),
warn = logger('app:tauri (template)', 'red')
const { copySync, renameSync, existsSync, mkdirSync, removeSync } = require('fs-extra')
const { resolve, join, normalize } = require('path')
const logger = require('./helpers/logger')
const log = logger('app:tauri', 'green')
const warn = logger('app:tauri (template)', 'red')
const injectConfFile = (injectPath, force, logging) => {
const injectConfFile = (injectPath, force, logging, directory) => {
const dir = normalize(join(injectPath, '..'))
const path = join(dir, 'tauri.conf.js')
if (existsSync(path) && force !== 'conf' && force !== 'all') {
@ -24,7 +24,7 @@ const injectConfFile = (injectPath, force, logging) => {
}
}
const injectTemplate = (injectPath, force, logging) => {
const injectTemplate = (injectPath, force, logging, directory) => {
if (existsSync(injectPath) && force !== 'template' && force !== 'all') {
warn(`Tauri dir (${injectPath}) not empty.
Run \`tauri init --force template\` to overwrite.`)
@ -70,18 +70,19 @@ Run \`tauri init --force template\` to overwrite.`)
* @param {string} type ['conf'|'template'|'all']
* @param {string|boolean} [force=false] - One of[false|'conf'|'template'|'all']
* @param {boolean} [logging=false]
* @param {string} directory
* @returns {boolean}
*/
const inject = (injectPath, type, force = false, logging = false) => {
const inject = (injectPath, type, force = false, logging = false, directory) => {
if (typeof type !== 'string' || typeof injectPath !== 'string') {
warn('- internal error. Required params missing.')
return false
}
if (type === 'conf' || type === 'all') {
injectConfFile(injectPath, force, logging)
injectConfFile(injectPath, force, logging, directory)
}
if (type === 'template' || type === 'all') {
injectTemplate(injectPath, force, logging)
injectTemplate(injectPath, force, logging, directory)
}
return true
}

View File

@ -1,7 +1,6 @@
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
module.exports.chain = function (chain, cfg) {
if (!cfg.tauri.embeddedServer.active) {
chain.optimization.splitChunks({
chunks: 'all',
@ -23,7 +22,7 @@ module.exports.chain = function (chain, cfg) {
}
})
chain.output.filename(`js/app.js`)
chain.output.filename('js/app.js')
if (cfg.ctx.prod) {
if (cfg.build.extractCSS) {

View File

@ -6,8 +6,8 @@
"tauri": "./mode/bin/tauri.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"devUp": ""
"test": "jest --coverage",
"lint-fix": "eslint --ext .js mode --fix"
},
"repository": {
"type": "git",
@ -25,7 +25,7 @@
"engines": {
"node": ">= 10.16.3",
"npm": ">= 6.6.0",
"yarn": ">= 1.17.3"
"yarn": ">= 1.19.1"
},
"dependencies": {
"@iarna/toml": "^2.2.3",
@ -41,5 +41,28 @@
"minimist": "^1.2.0",
"ms": "^2.1.2",
"webpack-merge": "^4.2.1"
}
},
"devDependencies": {
"dotenv": "^8.2.0",
"eslint": "^6.5.1",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "8.0.0",
"eslint-plugin-promise": "4.0.1",
"eslint-plugin-standard": "4.0.0",
"husky": "1.2.0",
"jest": "24.9.0",
"jest-mock-process": "^1.2.0",
"lint-staged": "^9.4.2",
"promise": "^8.0.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": [
"eslint --fix",
"git add"
]
}

30
tauri.conf.js Normal file
View File

@ -0,0 +1,30 @@
const
path = require('path'),
distDir = path.resolve(__dirname, './dist')
module.exports = function () {
return {
build: {
distDir: distDir,
APP_URL: 'http://localhost:4000' // must use a localhost server for now
},
ctx: {},
tauri: {
embeddedServer: {
active: true
},
bundle: {
active: true
},
whitelist: {
all: false
},
window: {
title: 'Tauri App'
},
security: {
csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\''
}
}
}
}

View File

@ -11,12 +11,12 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tauri-ui = { path = "../node_modules/@tauri-apps/tauri/bindings/rust" }
serde_json = "1.0.39"
# tauri-ui = { path = "../node_modules/@tauri-apps/tauri/bindings/rust" }
serde_json = "1.0.41"
serde = "1.0"
serde_derive = "1.0"
tiny_http = "0.6"
phf = "0.7.21"
phf = "0.8.0"
includedir = "0.5.0"
tauri = { path = "../node_modules/@tauri-apps/tauri/lib/rust" }

View File

@ -0,0 +1,35 @@
const { tauri } = require('mode/bin/tauri')
// const mockProcess = require('jest-mock-process')
describe('[CLI] tauri.js', () => {
it('displays a help message', async () => {
jest.spyOn(console, 'log')
jest.spyOn(process, 'exit').mockImplementation(() => true)
let result = tauri('help')
console.log(process.exit.mock.calls[0][0])
expect(process.exit.mock.calls[0][0]).toBe(0)
// console.log(console.log.mock.calls[0][0])
expect(!!console.log.mock.calls[0][0]).toBe(true)
result = tauri('--help')
// console.log(console.log.mock.calls[2][0])
expect(!!console.log.mock.calls[2][0]).toBe(true)
result = tauri('-h')
expect(!!console.log.mock.calls[3][0]).toBe(true)
jest.clearAllMocks()
})
it('will not run an unavailable command', async () => {
jest.spyOn(console, 'log')
let result = tauri('foo')
expect(console.log.mock.calls[0][0].split('.')[0]).toBe('Invalid command foo')
jest.clearAllMocks()
})
it('will pass on an available command', async () => {
jest.spyOn(console, 'log')
let result = tauri('init')
expect(console.log.mock.calls[0][0].split('.')[0]).toBe('[tauri]: running init')
jest.clearAllMocks()
})
})

10
test/jest/jest.setup.js Normal file
View File

@ -0,0 +1,10 @@
jest.setTimeout(1000)
global.Promise = require('promise')
setTimeout(() => {
// do nothing
}, 1)
require('dotenv').config({ path: '.env.jest' })

View File

@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev, (c) 2019 Quasar Framework
* Copyright (c) 2017 Serge Zaitsev, (c) 2019 Tauri Apps
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal

4570
yarn.lock

File diff suppressed because it is too large Load Diff