Skip to content

Commit

Permalink
chore(test): spec for nw.App.argv
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Aug 17, 2024
1 parent dbbfec2 commit 3c3ae3c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"base-volta-off-of-nwjs": "^1.0.5",
"commander": "^12.1.0",
"nw": "0.90.0",
"nw-builder": "^4.8.1"
"nw-builder": "^4.9.0"
},
"volta": {
"node": "22.0.0"
"node": "22.2.0"
}
}
22 changes: 22 additions & 0 deletions tests/fixtures/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('nw-app-argv').innerText = nw.App.argv;
});
</script>
<title>nw.App fixture</title>
</head>

<body>
<div>
<span>nw.App.argv: </span>
<span id="nw-app-argv"></span>
</div>
</body>

</html>
4 changes: 4 additions & 0 deletions tests/fixtures/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "basic",
"main": "index.html"
}
59 changes: 59 additions & 0 deletions tests/specs/api/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import path from 'node:path';

import selenium from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';

import * as nw from 'nw';

describe('nw.App', { timeout: Infinity }, async function () {
/**
* @type {chrome.Driver}
*/
let driver = undefined;

/**
* @type {string}
*/
let chromedriverPath = undefined;

beforeAll(async () => {
const options = new chrome.Options();
const args = [
`--nwapp=${path.resolve('tests', 'fixtures', 'app')}`,
'--headless=new',
];
options.addArguments(args);
chromedriverPath = await nw.findpath('chromedriver', { flavor: 'sdk' });
const service = new chrome.ServiceBuilder(chromedriverPath).build();
driver = chrome.Driver.createSession(options, service);
});

it('renders nw.App.argv', async () => {
/**
* `nw.App.argv` looks similar to the following:
*
* `"--allow-pre-commit-input,--disable-popup-blocking,--enable-automation,--enable-logging,--headless=new,--user-data-dir=/tmp/.io.nwjs.reD0Us"`
*
* @type {string}
*/
const argv = await driver.findElement(selenium.By.id('nw-app-argv')).getText();

/* There should be 6 command line arguments. */
const argvLength = argv.split(',').length;
expect(argvLength).toBe(6);

/* Since order does not matter, the `.toContain` matcher is used.*/
expect(argv).toContain('--allow-pre-commit-input');
expect(argv).toContain('--disable-popup-blocking');
expect(argv).toContain('--enable-automation');
expect(argv).toContain('--enable-logging');
expect(argv).toContain('--headless=new');
expect(argv).toContain('--user-data-dir=');
});

afterAll(async function () {
await driver.quit();
});

});

0 comments on commit 3c3ae3c

Please sign in to comment.