Skip to content

Commit 09c0797

Browse files
committed
Adds basic test cases and optional download link
1 parent a922baa commit 09c0797

11 files changed

Lines changed: 3153 additions & 47 deletions

File tree

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
{
2-
"name": "nodegui-qt-installer",
2+
"name": "@nodegui/qt-installer",
33
"version": "1.0.0",
44
"description": "A minimal qt installer for nodegui",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "tsc",
88
"start": "node dist/index.js",
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test": "jest --verbose"
1010
},
1111
"author": "atulanand94@gmail.com",
1212
"license": "ISC",
1313
"devDependencies": {
1414
"@types/7zip-min": "^1.1.0",
15+
"@types/jest": "^25.1.2",
1516
"@types/node-fetch": "^2.5.4",
1617
"@types/progress": "^2.0.3",
1718
"@typescript-eslint/eslint-plugin": "^2.19.0",
1819
"@typescript-eslint/parser": "^2.19.0",
1920
"eslint": "^6.8.0",
2021
"eslint-config-prettier": "^6.10.0",
2122
"eslint-plugin-prettier": "^3.1.2",
23+
"jest": "^25.1.0",
2224
"prettier": "^1.19.1",
25+
"ts-jest": "^25.2.0",
2326
"typescript": "^3.7.5"
2427
},
2528
"dependencies": {
2629
"7zip-min": "^1.1.1",
2730
"mkdirp": "^1.0.3",
2831
"node-fetch": "^2.6.0",
29-
"progress": "^2.0.3"
32+
"progress": "^2.0.3",
33+
"tempy": "^0.3.0"
3034
}
3135
}

src/index.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,2 @@
1-
import { download } from './downloader';
2-
import { extract } from './extractor';
3-
import os from 'os';
4-
import metadata from './metadata.json';
5-
6-
type SupportedOs = 'linux' | 'win32' | 'darwin';
7-
const setupQt = async (): Promise<void> => {
8-
const currentOs = os.platform() as SupportedOs;
9-
const downloadLink = metadata[currentOs];
10-
const archivePath = './out/test/123/download.7zip';
11-
const extractDir = './out/test2/extracted';
12-
await download(downloadLink, archivePath, { name: 'Qt for Mac' });
13-
await extract(archivePath, extractDir);
14-
};
15-
16-
const main = async (): Promise<void> => {
17-
await setupQt();
18-
};
19-
20-
main()
21-
.then(console.log)
22-
.catch(console.error);
1+
import './types';
2+
export { setupQt } from './setup';

src/setup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { download } from './downloader';
2+
import { extract } from './extractor';
3+
import metadata from './metadata.json';
4+
import tempy from 'tempy';
5+
6+
type SupportedOs = 'linux' | 'win32' | 'darwin';
7+
type SetupOptions = {
8+
qtDir: string;
9+
downloadLink?: string;
10+
osType: SupportedOs;
11+
};
12+
13+
export async function setupQt(options: SetupOptions): Promise<string> {
14+
const downloadLink = options.downloadLink || metadata[options.osType];
15+
const archivePath = tempy.file({ extension: '7z' });
16+
const extractDir = options.qtDir;
17+
await download(downloadLink, archivePath, { name: 'Qt for Mac' });
18+
await extract(archivePath, extractDir);
19+
console.log(`Qt was setup successfully. QtDir: ${extractDir}`);
20+
return extractDir;
21+
}

src/tests/darwin.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import { setupQt } from '../index';
4+
import { outputDir, TIMEOUT } from './utils';
5+
6+
describe('Setup QT for darwin', () => {
7+
const osType = 'darwin';
8+
const qtDir = outputDir(osType);
9+
let outPath = '';
10+
11+
beforeAll(async () => {
12+
outPath = await setupQt({ qtDir, osType });
13+
}, TIMEOUT);
14+
15+
test('check if output path is same as specified: ', () => {
16+
expect(outPath).toBe(qtDir);
17+
});
18+
19+
test('check if qt exists', () => {
20+
const expectedPath = `5.13.0/clang_64`;
21+
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
22+
expect(doesQtExist).toBe(true);
23+
});
24+
});

src/tests/linux.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import { setupQt } from '../index';
4+
import { outputDir, TIMEOUT } from './utils';
5+
6+
describe('Setup QT for linux', () => {
7+
const osType = 'linux';
8+
const qtDir = outputDir(osType);
9+
let outPath = '';
10+
11+
beforeAll(async () => {
12+
outPath = await setupQt({ qtDir, osType });
13+
}, TIMEOUT);
14+
15+
test('check if output path is same as specified: ', () => {
16+
expect(outPath).toBe(qtDir);
17+
});
18+
19+
test('check if qt exists', () => {
20+
const expectedPath = `5.13.0/gcc_64`;
21+
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
22+
expect(doesQtExist).toBe(true);
23+
});
24+
});

src/tests/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import path from 'path';
2+
3+
export const TIMEOUT = 60000;
4+
export const outputDir = (osName: string): string => path.resolve(__dirname, '..', '..', 'out', osName);

src/tests/win32.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import { setupQt } from '../index';
4+
import { outputDir, TIMEOUT } from './utils';
5+
6+
describe('Setup QT for win32', () => {
7+
const osType = 'win32';
8+
const qtDir = outputDir(osType);
9+
let outPath = '';
10+
11+
beforeAll(async () => {
12+
outPath = await setupQt({ qtDir, osType });
13+
}, TIMEOUT);
14+
15+
test('check if output path is same as specified: ', () => {
16+
expect(outPath).toBe(qtDir);
17+
});
18+
19+
test('check if qt exists', () => {
20+
const expectedPath = `5.13.0/msvc2017_64`;
21+
const doesQtExist = fs.existsSync(path.resolve(qtDir, expectedPath));
22+
expect(doesQtExist).toBe(true);
23+
});
24+
});
File renamed without changes.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"moduleResolution": "node",
1515
"resolveJsonModule": true
1616
},
17-
"include": ["src"]
17+
"include": ["src/index.ts"]
1818
}

0 commit comments

Comments
 (0)