diff --git a/src/main/extension-updater/__tests__/extension-updater.test.ts b/src/main/extension-updater/__tests__/extension-updater.test.ts index 73b8886fd3..794aebd803 100644 --- a/src/main/extension-updater/__tests__/extension-updater.test.ts +++ b/src/main/extension-updater/__tests__/extension-updater.test.ts @@ -7,10 +7,11 @@ import { BundledExtensionUpdater } from "../bundled-extension-updater"; import fs from "fs"; import mockFs from "mock-fs"; import nock from "nock"; +import path from "path"; const mockOpts = { "some-user-data-directory": { - "some-file.tgz": "file content here", + "some-file.tgz": mockFs.load(path.resolve(__dirname, "./survey-mock.tgz")), }, "extension-updates": { "file.txt": "text", @@ -47,7 +48,7 @@ describe("BundledExtensionUpdater", () => { expect(exist).toBeTruthy(); }); - it.only("Should skip download if no file found on server", () => { + it("Should skip download if no file found on server", () => { mockFs(mockOpts); nock("http://my-example-url.com") @@ -98,4 +99,30 @@ describe("BundledExtensionUpdater", () => { expect(exist).toBeTruthy(); }); + + it.only("Should unpack downloaded tar file", async () => { + mockFs(mockOpts); + + nock("http://my-example-url.com") + .get("/some-file.tgz") + .replyWithFile(200, `./some-user-data-directory/some-file.tgz`, { + "Content-Type": "application/tar", + }); + + await new BundledExtensionUpdater({ + name: "test-extension", + version: "0.0.1", + downloadUrl: "http://my-example-url.com/some-file.tgz", + }, "./extension-updates").update(); + + fs.readdirSync("./extension-updates/").forEach(file => { + console.log(file); + }); + + const existTar = fs.existsSync("./extension-updates/test-extension-0.0.1.tgz"); + const existFolder = fs.existsSync("./extension-updates/test-extension-0.0.1"); + + expect(existTar).toBeTruthy(); + expect(existFolder).toBeTruthy(); + }); }); diff --git a/src/main/extension-updater/__tests__/survey-mock.tgz b/src/main/extension-updater/__tests__/survey-mock.tgz new file mode 100644 index 0000000000..d3f05bbaac Binary files /dev/null and b/src/main/extension-updater/__tests__/survey-mock.tgz differ diff --git a/src/main/extension-updater/bundled-extension-updater.ts b/src/main/extension-updater/bundled-extension-updater.ts index 92bfec43b0..02f741805c 100644 --- a/src/main/extension-updater/bundled-extension-updater.ts +++ b/src/main/extension-updater/bundled-extension-updater.ts @@ -9,6 +9,7 @@ import request from "request"; import logger from "../logger"; import path from "path"; import { noop } from "../../common/utils"; +import tar from "tar-fs"; type Extension = { name: string @@ -28,6 +29,7 @@ export class BundledExtensionUpdater { public async update() { await this.download(); await this.removePreviousUpdateFolder(); + // await this.unpackTar(); } private get filePath() { @@ -85,4 +87,13 @@ export class BundledExtensionUpdater { }); } } + + private async unpackTar() { + logger.info(`[EXTENSION-UPDATER]: Unpacking '${this.filePath}' into '${this.folderPath}'`); + + const extract = tar.extract("./extension-updates/"); + + // console.log(this.filePath.replace("./", "")) + fs.createReadStream("extension-updates/file.txt").pipe(extract).end(); + } }