Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): port nw-builder tests #178

Merged
merged 12 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: ci

on:
pull_request:
branches: [ main ]
branches:
- main

concurrency:
group: ${{ github.ref }}
Expand All @@ -12,7 +13,10 @@ jobs:
test:
strategy:
matrix:
os: [macos-14, ubuntu-22.04, windows-2022]
os:
- macos-14
- ubuntu-22.04
- windows-2022
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -25,8 +29,6 @@ jobs:
with:
node-version: ${{ env.NODE_VER }}
cache: "npm"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: npm ci --nwjs-build-type=sdk
- name: Run tests
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
nwjs*
test/fixture
62 changes: 45 additions & 17 deletions src/decompress.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
import fs from "node:fs";
import path from "node:path";
import process from "node:process";

import { beforeAll, describe, it } from "vitest";
import { afterAll, beforeAll, describe, expect, it } from "vitest";

import * as nw from "../src/index.js";
import decompress from "./decompress.js";
import request from "./request.js";
import util from './util.js';

describe("get/decompress", function () {
describe("get/decompress", async function () {

let tarUrl = "https://dl.nwjs.io/v0.83.0/nwjs-sdk-v0.83.0-linux-x64.tar.gz";
let zipUrl = "https://dl.nwjs.io/v0.83.0/nwjs-sdk-v0.83.0-osx-x64.zip";
let nwFilePath = '';
let nwDirPath = '';
let nwOutPath = "./test/fixture/cache";

beforeAll(async function () {
await fs.promises.mkdir("./test/fixture/cache", {recursive: true});

await request(tarUrl, "./test/fixture/cache/nw.tar.gz");
await request(zipUrl, "./test/fixture/cache/nw.zip");
}, Infinity);
afterAll(async function () {
await fs.promises.rm(nwOutPath, { recursive: true, force: true });
});

it("decompresses a Linux tarball", async function () {
await decompress("./test/fixture/cache/nw.tar.gz", "./test/fixture/cache");
beforeAll(async function () {
nwDirPath = await nw.findpath('all', { flavor: 'sdk' });

const cacheExists = await util.fileExists(nwOutPath)
if (!cacheExists) {
await fs.promises.mkdir(nwOutPath);
}

if (process.platform === 'linux') {
nwFilePath = nwDirPath + '.tar.gz';
} else {
nwFilePath = nwDirPath + '.zip';
}
});

it("decompresses a NW.js binary", async function () {
await decompress(nwFilePath, nwOutPath);
}, Infinity);

it("decompresses a MacOS zip", async function () {
await decompress("./test/fixture/cache/nw.zip", "./test/fixture/cache");
}, Infinity);
});
it.runIf(process.platform === 'darwin')("preserves symlinks on macos", async function () {
const frameworksPath = path.resolve(process.cwd(), nwOutPath, nwDirPath, "nwjs.app", "Contents", "Frameworks", "nwjs Framework.framework");
const symlinks = [
path.join(frameworksPath, "Helpers"),
path.join(frameworksPath, "Libraries"),
path.join(frameworksPath, "nwjs Framework"),
path.join(frameworksPath, "Resources"),
path.join(frameworksPath, "Versions", "Current"),
];

for (const symlink of symlinks) {
const stats = await fs.promises.lstat(symlink);
expect(stats.isSymbolicLink()).toEqual(true);
}
});
});
2 changes: 1 addition & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import axios from "axios";
*
* @async
* @function
*
*
* @param {string} url - Download server
* @param {string} filePath - file path of downloaded content
* @return {Promise<void>}
Expand Down
20 changes: 5 additions & 15 deletions src/request.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import fs from "node:fs";

import { afterEach, beforeAll, describe, expect, it } from "vitest";
import { describe, expect, it } from "vitest";

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

describe("get/request", function () {
describe.skip("get/request", function () {

let url = "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json"
const filePath = "./test/fixture/request.test.json";

afterEach(async function () {
await fs.promises.rm(filePath, { force: true });
});

beforeAll(async function () {
await fs.promises.mkdir('./test/fixture', { recursive: true });
});
const filePath = "./test/fixture/cache/request.test.json";

it("downloads from specific url", async function () {
await request(url, filePath);
expect(util.fileExists(filePath)).resolves.toBe(true);
}, Infinity);
});
});
}, Infinity);
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/selenium.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("run", async function () {
beforeAll(async function () {
const options = new chrome.Options();
const seleniumArgs = [
`--nwapp=${path.resolve("test", "app")}`,
`--nwapp=${path.resolve("test", "fixture" , "app")}`,
"--headless=new",
];

Expand Down