Skip to content

Commit

Permalink
fix(findpath): do not look for symlink (#147)
Browse files Browse the repository at this point in the history
On Windows, the symlink is not created if user does not have
Administrator privileges. Look for actual file path instead of symlink.
  • Loading branch information
ayushmanchhabra authored Apr 14, 2024
1 parent c53ab35 commit 75a9fc0
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 38 deletions.
11 changes: 10 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
directory: "."
schedule:
interval: "daily"
versioning-strategy: increase
groups:
npm:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "daily"
groups:
gha:
patterns:
- "*"
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
cancel-in-progress: true

jobs:
e2e:
test:
strategy:
matrix:
os: [macos-13, ubuntu-22.04, windows-2022]
Expand All @@ -29,5 +29,5 @@ jobs:
run: corepack enable
- name: Install dependencies
run: npm ci --nwjs-build-type=sdk
- name: Run test
run: npm test
- name: Run tests
run: npm t
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Changed

- `findpath` looks for actual path and not symlink. On Windows, if user does not have Administrator privileges, symlink is not created, then `findpath` fails to find the file path.

- `findpath` is async with return type `Promise<string>`.
- `findpath` has a secondary options argument. This is useful when trying to get the file path to ChromeDriver:

```js
const nwPath = await findpath('chromedriver', { flavor: 'sdk' });
```


## [0.86.0-2]

### Changed
Expand Down
19 changes: 8 additions & 11 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import path from 'node:path';
import process from 'node:process';
import url from 'node:url';

import parse from './parse.js';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

/**
Expand Down Expand Up @@ -43,29 +45,24 @@ const EXE_NAME = {
* Get the platform dependant path of the NW.js or ChromeDriver binary.
*
* @param {'nwjs' | 'chromedriver'} executable Path to NW.js or Chromedriver executable.
* @return {string}
* @return {Promise<string>}
*/
function findpath(executable = 'nwjs') {
const nwDir = path.resolve(__dirname, '..', 'nwjs');
async function findpath(executable = 'nwjs', options = {}) {
options = await parse(options);
const nwDir = path.resolve(__dirname, '..', `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform}-${options.arch}`);

/**
* File path to executable.
*
* @type {string}
*/
let binPath = '';

/**
* Host operating system
*
* @type {NodeJS.Platform}
*/
let hostOs = PLATFORM_KV[process.env.npm_config_nwjs_platform || process.env.NWJS_PLATFORM || process.platform];

/**
* Get the platform dependant path of the NW.js binary.
*/
function findNwjs() {
binPath = path.resolve(nwDir, EXE_NAME[hostOs]);
binPath = path.resolve(nwDir, EXE_NAME[options.platform]);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions test/findpath.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'node:fs';
import { expect, test } from 'vitest';

import util from '../src/util.js';

test('nwjs has downloaded and been extracted', function () {
util.findpath('nwjs').then(function (path) {
expect(fs.existsSync(path)).toEqual(true);
})
.catch((error) => {
console.log(error);
});
});
8 changes: 0 additions & 8 deletions test/index.test.js

This file was deleted.

38 changes: 23 additions & 15 deletions test/selenium.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import assert from "node:assert";
import path from "node:path";

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

import util from "../src/util.js";

const { Driver, ServiceBuilder, Options } = chrome;

describe("run", async () => {
describe("run", async function () {
let driver = undefined;

it("should run post install", async () => {
const options = new Options();
const args = [
beforeAll(async function () {
const options = new chrome.Options();
const seleniumArgs = [
`--nwapp=${path.resolve("test", "app")}`,
"--headless=new",
];
options.addArguments(args);

const chromedriverPath = util.findpath("chromedriver");
options.addArguments(seleniumArgs);

const chromedriverPath = await util.findpath("chromedriver", { flavor: 'sdk' });
const service = new chrome.ServiceBuilder(chromedriverPath).build();

driver = chrome.Driver.createSession(options, service);
});

const service = new ServiceBuilder(chromedriverPath).build();
it("should run post install", async function () {
const textElement = await driver.findElement(selenium.By.id('test'));

driver = Driver.createSession(options, service);
const text = await driver.findElement(By.id("test")).getText();
assert.strictEqual(text, "Hello, World! Is anyone out there?");
const text = await textElement.getText();

expect(text).toEqual('Hello, World! Is anyone out there?');
}, { timeout: Infinity });

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

});

0 comments on commit 75a9fc0

Please sign in to comment.