-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): port nw-builder tests (#178)
Ports: nwutils/nw-builder@f802947
- Loading branch information
1 parent
6d0e264
commit e086cdf
Showing
8 changed files
with
58 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
node_modules | ||
nwjs* | ||
test/fixture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters