1- const os = require ( "os" ) ;
2- const path = require ( "path" ) ;
3- const { expect } = require ( "chai" ) ;
4- const { spawn, spawnSync } = require ( "child_process" ) ;
5- const { Builder, By, Capabilities } = require ( "selenium-webdriver" ) ;
1+ import os from "os" ;
2+ import path from "path" ;
3+ import { expect } from "chai" ;
4+ import { spawn , spawnSync } from "child_process" ;
5+ import { Builder , By , Capabilities } from "selenium-webdriver" ;
6+ import { fileURLToPath } from "url" ;
7+
8+ const __dirname = fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
69
710// create the path to the expected application binary
811const application = path . resolve (
@@ -21,22 +24,22 @@ let driver;
2124
2225// keep track of the tauri-driver process we start
2326let tauriDriver ;
27+ let exit = false ;
2428
25- before ( async function ( ) {
29+ before ( async function ( ) {
2630 // set timeout to 2 minutes to allow the program to build if it needs to
27- this . timeout ( 120000 )
31+ this . timeout ( 120000 ) ;
2832
2933 // ensure the program has been built
30- spawnSync (
31- "pnpm" ,
32- [ "build" ] ,
33- { cwd : path . resolve ( __dirname , "../../.." ) , stdio : 'inherit' , shell : true }
34- )
35- spawnSync (
36- "cargo" ,
37- [ "build" , "--features" , "tauri/custom-protocol" ] ,
38- { cwd : path . resolve ( __dirname , "../../../src-tauri" ) , stdio : 'inherit' }
39- ) ;
34+ spawnSync ( "pnpm" , [ "build" ] , {
35+ cwd : path . resolve ( __dirname , "../../.." ) ,
36+ stdio : "inherit" ,
37+ shell : true ,
38+ } ) ;
39+ spawnSync ( "cargo" , [ "build" , "--features" , "tauri/custom-protocol" ] , {
40+ cwd : path . resolve ( __dirname , "../../../src-tauri" ) ,
41+ stdio : "inherit" ,
42+ } ) ;
4043
4144 // start tauri-driver
4245 tauriDriver = spawn (
@@ -56,7 +59,7 @@ before(async function() {
5659 . build ( ) ;
5760} ) ;
5861
59- after ( async function ( ) {
62+ after ( async function ( ) {
6063 // stop the webdriver session
6164 await driver . quit ( ) ;
6265
@@ -77,12 +80,14 @@ describe("Hello Tauri", () => {
7780
7881 it ( "should be easy on the eyes" , async ( ) => {
7982 // selenium returns color css values as rgb(r, g, b)
80- const text = await driver . findElement ( By . css ( "body" ) ) . getCssValue ( "background-color" ) ;
83+ const text = await driver
84+ . findElement ( By . css ( "body" ) )
85+ . getCssValue ( "background-color" ) ;
8186
8287 const rgb = text . match ( / ^ r g b \( (?< r > \d + ) , (?< g > \d + ) , (?< b > \d + ) \) $ / ) . groups ;
83- expect ( rgb ) . to . have . all . keys ( 'r' , 'g' , 'b' ) ;
88+ expect ( rgb ) . to . have . all . keys ( "r" , "g" , "b" ) ;
8489
85- const luma = 0.2126 * rgb . r + 0.7152 * rgb . g + 0.0722 * rgb . b ;
86- expect ( luma ) . to . be . lessThan ( 100 )
90+ const luma = 0.2126 * rgb . r + 0.7152 * rgb . g + 0.0722 * rgb . b ;
91+ expect ( luma ) . to . be . lessThan ( 100 ) ;
8792 } ) ;
8893} ) ;
0 commit comments