1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/functional/sanity/nullstorage.ts
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

76 lines
2.9 KiB
TypeScript

import {readFile} from '../lib/test.utils';
import {createTarballHash} from "../../../src/lib/crypto-utils";
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
import generatePkg from '../fixtures/package';
import {DIST_TAGS} from '../../../src/lib/constants';
function getBinary() {
return readFile('../fixtures/binary');
}
export default function (server, server2) {
const PKG_NAME = 'test-nullstorage2';
const PKG_VERSION = '0.0.1';
// const TARBALL = `${PKG_NAME}-file.name`;
describe('should test a scenario when tarball is being fetch from uplink', () => {
describe(`should check whether ${PKG_NAME} is on server1`, () => {
test('should fails on fetch non-existent package on server1', () => {
return server.getPackage('test-nullstorage-nonexist').status(HTTP_STATUS.NOT_FOUND)
.body_error(API_ERROR.NO_PACKAGE);
});
});
describe(`should check whether ${PKG_NAME} is on server2`, () => {
beforeAll(function() {
return server2.addPackage(PKG_NAME);
});
test('should create a new package on server2', () => {/* test for before() */});
test('should fails on download a non existent tarball from server1', () => {
return server.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.NOT_FOUND)
.body_error(/no such file/);
});
describe(`should succesfully publish ${PKG_NAME} package on server2`, () => {
beforeAll(function() {
return server2.putTarball(PKG_NAME, TARBALL, getBinary()).status(HTTP_STATUS.CREATED).body_ok(/.*/);
});
beforeAll(function() {
let pkg = generatePkg(PKG_NAME);
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
return server2.putVersion(PKG_NAME, PKG_VERSION, pkg)
.status(HTTP_STATUS.CREATED).body_ok(/published/);
});
test(`should publish a new version for ${PKG_NAME} on server 2`, () => {/* test for before() */});
test(`should fetch the newly created published tarball for ${PKG_NAME} from server1 on server2`, () => {
return server.getTarball(PKG_NAME, TARBALL)
.status(HTTP_STATUS.OK)
.then(function(body) {
expect(body).toEqual(getBinary());
});
});
test(`should fetch metadata for ${PKG_NAME} match from server1`, () => {
return server.getPackage(PKG_NAME)
.status(HTTP_STATUS.OK)
.then(function(body) {
expect(body.name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
expect(body.versions[PKG_VERSION].dist.tarball).toBe(`http://${DOMAIN_SERVERS}:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`);
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
});
});
});
});
});
}