diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e52740f..43c067b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,8 @@ name: ci on: pull_request: - branches: [ main ] + branches: + - main concurrency: group: ${{ github.ref }} @@ -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: @@ -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 diff --git a/.gitignore b/.gitignore index 337067c..ff98265 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules nwjs* -test/fixture diff --git a/src/decompress.test.js b/src/decompress.test.js index 84e1f07..79aa431 100644 --- a/src/decompress.test.js +++ b/src/decompress.test.js @@ -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); -}); \ No newline at end of file + 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); + } + }); +}); diff --git a/src/request.js b/src/request.js index 3a23ed9..bc57684 100644 --- a/src/request.js +++ b/src/request.js @@ -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} diff --git a/src/request.test.js b/src/request.test.js index 6d96853..fd84826 100644 --- a/src/request.test.js +++ b/src/request.test.js @@ -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); diff --git a/test/app/index.html b/test/fixture/app/index.html similarity index 100% rename from test/app/index.html rename to test/fixture/app/index.html diff --git a/test/app/package.json b/test/fixture/app/package.json similarity index 100% rename from test/app/package.json rename to test/fixture/app/package.json diff --git a/test/selenium.test.js b/test/selenium.test.js index 0157614..f9beecb 100644 --- a/test/selenium.test.js +++ b/test/selenium.test.js @@ -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", ];