Skip to content

Commit ff4211f

Browse files
committed
feat: fix app package property tests
1 parent a12817e commit ff4211f

File tree

7 files changed

+62
-27
lines changed

7 files changed

+62
-27
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Unit tests with `npm run test`
7979
### End-to-end (e2e) tests
8080

8181
For e2e tests, we use webdriver and an electron plugin to automate testing.
82-
It requires a packaged build to complete the tests.
82+
**It requires a packaged build to run the tests!**
8383

8484
To run them locally, package the source first (and after making any changes to anything other than `tests`), then run the e2e tests with `wdio`
8585

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepare": "husky",
2323
"storybook": "storybook dev -p 6006",
2424
"build-storybook": "storybook build",
25-
"wdio": "cross-env NODE_ENV=test wdio run ./wdio.conf.ts",
25+
"wdio": "wdio run ./wdio.conf.ts",
2626
"docs:nodeSpec": "typedoc --plugin typedoc-plugin-markdown --name \"Node Spec examples\" --readme src/common/index.md --entryDocument index.md --out docs src/common/*"
2727
},
2828
"devDependencies": {

src/main/files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const getAssetsFolder = (): string => {
230230
return path.resolve(__dirname, '..', '..', 'assets');
231231
}
232232

233-
if (process.env.NODE_ENV === 'test') {
233+
if (process.env.TEST === 'true') {
234234
return 'assets';
235235
}
236236

src/main/main.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ if (process.env.NODE_ENV === 'development') {
4141
}
4242

4343
// todo: when moving from require to imports
44-
// const isTest = process.env.NODE_ENV === 'test';
45-
// if (isTest) {
46-
// console.log('NODE_ENV=TEST... requiring wdio-electron-service/main');
47-
// require('wdio-electron-service/main');
48-
// }
44+
const isTest = process.env.TEST === 'true';
45+
if (isTest) {
46+
logger.info('env.TEST=true... calling import(wdio-electron-service/main)');
47+
import('wdio-electron-service/main');
48+
}
4949

5050
// todo: Turned off when switching to ESM modules. Do we need this?
5151
// https://www.electronforge.io/config/makers/squirrel.windows#handling-startup-events
@@ -76,8 +76,6 @@ export const getMenuBuilder = () => menuBuilder;
7676
const isDevelopment =
7777
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
7878

79-
const isTest = process.env.NODE_ENV === 'test';
80-
8179
// if (isDevelopment) {
8280
// require('electron-debug')();
8381
// }

src/main/preload.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import { CHANNELS_ARRAY } from './messenger';
1010
import type { AddNodePackageNodeService } from './nodePackageManager';
1111
import type { ThemeSetting } from './state/settings';
1212

13-
// todo: when moving from require to imports
14-
// const isTest = process.env.NODE_ENV === 'test';
15-
// if (isTest) {
16-
// console.log('NODE_ENV=TEST... requiring wdio-electron-service/main');
17-
// require('wdio-electron-service/preload');
18-
// }
13+
const isTest = process.env.TEST === 'true';
14+
if (isTest) {
15+
console.log('NODE_ENV=TEST... requiring wdio-electron-service/main');
16+
import('wdio-electron-service/preload');
17+
}
1918

2019
contextBridge.exposeInMainWorld('electron', {
2120
SENTRY_DSN: process.env.SENTRY_DSN,

test/specs/test.e2e.ts

+44-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global $ */
22
import { expect } from '@wdio/globals';
3-
// import { browser } from 'wdio-electron-service';
3+
import { browser } from 'wdio-electron-service';
44

55
describe('Splash screen tests', () => {
66
it('application should open to splash screen with welcome message', async () => {
@@ -15,12 +15,48 @@ describe('Splash screen tests', () => {
1515
await expect(elAddFirstNodeTitle).toBeDisplayed();
1616
await expect(elAddFirstNodeTitle).toHaveText('Add your first node');
1717
});
18+
});
19+
20+
describe('App build property tests', () => {
21+
// More Electron api test examples
22+
// https://github.com/webdriverio-community/wdio-electron-service/blob/main/docs/electron-apis/mocking-apis.md
23+
it('app name should be set', async () => {
24+
expect(await browser.electron.execute((electron) => {
25+
return electron.app.getName();
26+
})).toEqual('NiceNode');
27+
});
28+
29+
it('app version should be set and greater than 6.0.0', async () => {
30+
expect(await browser.electron.execute((electron) => {
31+
return electron.app.getVersion();
32+
})).toBeDefined();
33+
expect(await browser.electron.execute((electron) => {
34+
return electron.app.getVersion();
35+
}) > '6.0.0').toBeTruthy();
36+
});
37+
38+
it('app menu should be contain NiceNode and Help', async () => {
39+
const isNiceNodeMenuItemExists = await browser.electron.execute((electron) => {
40+
// console.log('menu', electron.app.applicationMenu)
41+
return electron.app.applicationMenu.items.some((item) => {
42+
// console.log('item', item)
43+
return item.label === 'NiceNode';
44+
});
45+
})
46+
expect(isNiceNodeMenuItemExists).toBeTruthy();
47+
const isHelpMenuItemExists = await browser.electron.execute((electron) => {
48+
// console.log('menu', electron.app.applicationMenu)
49+
return electron.app.applicationMenu.items.some((item) => {
50+
// console.log('item', item)
51+
return item.label === 'Help';
52+
});
53+
})
54+
expect(isHelpMenuItemExists).toBeTruthy();
55+
});
1856

19-
// todo: when moving from require to imports
20-
// it('app name should be set', async () => {
21-
// await browser.electron.execute(async (electron) => {
22-
// const appName = await electron.app.getName();
23-
// await expect(appName).toEqual('NiceNode');
24-
// });
25-
// });
57+
it('logs dir path should contain logs', async () => {
58+
expect(await browser.electron.execute((electron) => {
59+
return electron.app.getPath('logs');
60+
})).toContain('logs');
61+
});
2662
});

wdio.conf.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ if (process.platform === 'darwin') {
1515
appBinaryPath = path.join('out', `NiceNode-win32-${arch}`, 'nice-node.exe')
1616
}
1717

18+
process.env.TEST = 'true';
19+
1820
export const config: Options.Testrunner = {
1921
//
2022
// ====================
@@ -73,9 +75,9 @@ export const config: Options.Testrunner = {
7375
browserName: 'electron',
7476
// Electron service options
7577
// see https://webdriver.io/docs/wdio-electron-service/#configuration
76-
'goog:chromeOptions': {
77-
args:['--headless', '--disable-dev-shm-usage', '--no-sandbox', '--disable-gpu', '--window-size=1680,1050']
78-
},
78+
// 'goog:chromeOptions': {
79+
// args:['--headless', '--disable-dev-shm-usage', '--no-sandbox', '--disable-gpu', '--window-size=1680,1050']
80+
// },
7981
'wdio:electronServiceOptions': {
8082
// custom application args
8183
// See https://github.com/webdriverio-community/wdio-electron-service#appargs

0 commit comments

Comments
 (0)