2018-09-01 14:40:42 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2022-04-04 21:21:49 +00:00
|
|
|
import * as smartnpm from '../ts/index.js';
|
|
|
|
import { NpmRegistry } from '../ts/index.js';
|
2017-08-14 15:50:48 +00:00
|
|
|
|
2019-09-06 09:12:23 +00:00
|
|
|
let npmRegistry: smartnpm.NpmRegistry;
|
|
|
|
let verdaccioRegistry: smartnpm.NpmRegistry;
|
2018-09-01 14:40:42 +00:00
|
|
|
let testPackage: smartnpm.NpmPackage;
|
2017-08-15 15:03:21 +00:00
|
|
|
|
2019-09-06 09:12:23 +00:00
|
|
|
// lets test things with the standard npm registry
|
2017-08-15 15:03:21 +00:00
|
|
|
tap.test('should create valid instances', async () => {
|
2019-09-06 09:12:23 +00:00
|
|
|
npmRegistry = new smartnpm.NpmRegistry();
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(npmRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
2017-08-15 15:03:21 +00:00
|
|
|
|
2020-03-17 00:38:58 +00:00
|
|
|
testPackage = new smartnpm.NpmPackage(npmRegistry);
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(testPackage).toBeInstanceOf(smartnpm.NpmPackage);
|
2018-09-01 14:40:42 +00:00
|
|
|
});
|
2017-08-15 15:03:21 +00:00
|
|
|
|
2018-02-14 22:51:08 +00:00
|
|
|
tap.test('should produce a valid search string and this return npmts', async () => {
|
2020-03-17 00:38:58 +00:00
|
|
|
const packages = await npmRegistry.searchOnNpm({
|
2020-10-02 13:28:39 +00:00
|
|
|
name: '@pushrocks/smartupdate',
|
2018-09-01 14:40:42 +00:00
|
|
|
});
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(packages[0].name).toEqual('@pushrocks/smartupdate');
|
2018-09-01 14:40:42 +00:00
|
|
|
});
|
2017-08-14 15:50:48 +00:00
|
|
|
|
2019-09-06 09:12:23 +00:00
|
|
|
// lets test things with the verdaccio registry
|
|
|
|
tap.test('should create a verdaccio registry', async () => {
|
|
|
|
verdaccioRegistry = new NpmRegistry({
|
2020-10-02 13:28:39 +00:00
|
|
|
npmRegistryUrl: 'https://verdaccio.lossless.one',
|
2019-09-06 09:12:23 +00:00
|
|
|
});
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(verdaccioRegistry).toBeInstanceOf(smartnpm.NpmRegistry);
|
2019-09-06 09:12:23 +00:00
|
|
|
});
|
|
|
|
|
2020-03-17 00:38:58 +00:00
|
|
|
tap.test('should get package from verdaccio', async () => {
|
2019-09-06 11:22:54 +00:00
|
|
|
const npmPackage = await verdaccioRegistry.getPackageInfo('@pushrocks/smartupdate');
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(npmPackage.license).toEqual('MIT');
|
2019-09-06 09:12:23 +00:00
|
|
|
});
|
|
|
|
|
2020-03-17 00:38:58 +00:00
|
|
|
tap.test('should get a specific file from a package', async () => {
|
2021-05-05 11:56:12 +00:00
|
|
|
const wantedFile = await verdaccioRegistry.getFileFromPackage(
|
2020-03-17 00:38:58 +00:00
|
|
|
'@pushrocks/websetup',
|
2022-04-04 21:21:49 +00:00
|
|
|
'./ts/index.ts'
|
2020-03-17 00:38:58 +00:00
|
|
|
);
|
2021-05-05 11:56:12 +00:00
|
|
|
console.log(wantedFile.contentBuffer.toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should get a specific file from a package', async () => {
|
|
|
|
const wantedFiles = await verdaccioRegistry.getFilesFromPackage(
|
|
|
|
'@pushrocks/websetup',
|
|
|
|
'ts/'
|
|
|
|
);
|
|
|
|
for(const file of wantedFiles) {
|
|
|
|
console.log(file.path);
|
|
|
|
}
|
2020-03-17 00:38:58 +00:00
|
|
|
});
|
|
|
|
|
2021-06-07 11:59:56 +00:00
|
|
|
tap.test('should not get a nonexisting file from a package', async () => {
|
|
|
|
const wantedFileNotThere = await verdaccioRegistry.getFileFromPackage(
|
|
|
|
'@pushrocks/websetup',
|
|
|
|
'ts/notthere'
|
|
|
|
);
|
2022-04-04 21:21:49 +00:00
|
|
|
expect(wantedFileNotThere).toBeNull();
|
2021-06-07 11:59:56 +00:00
|
|
|
});
|
|
|
|
|
2018-09-01 14:40:42 +00:00
|
|
|
tap.start();
|