0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-13 22:48:31 -05:00
verdaccio/test/functional/uplinks/cache.ts
Juan Picado 69d7df20d8
build: enable pnp yarn2 (#2253)
* chore: enable pnp yarn

* chore: ignore pnp

* fix type issues on run eslint

* add missing dependency and fix some errors

* fix most of the errors

some were just disabled, already fixed in master

* add missing jest-config

* update jest@26 align with other deps

* add missing @babel/register

* clean up

* use yarn node

* use yarn node on release

* chore: add husky 6

* chore: add husky 6

* chore: lint-stage

* chore: test

* chore: add hook git

* chore: test

* chore: test

* update deps

* chore: fix commit lint

* fix docker run

* update git ignore
2021-05-13 23:13:57 +02:00

93 lines
2.6 KiB
TypeScript

import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
import { readFile } from '../lib/test.utils';
import { HTTP_STATUS } from '../../../src/lib/constants';
import { TARBALL } from '../config.functional';
import { createTarballHash } from '../../../src/lib/crypto-utils';
import requirePackage from '../fixtures/package';
function getBinary() {
return readFile('../fixtures/binary');
}
const STORAGE = '../store/test-storage3';
const PKG_GH131 = 'pkg-gh131';
const PKG_GH1312 = 'pkg-gh1312';
function isCached(pkgName, tarballName) {
const pathCached = path.join(__dirname, STORAGE, pkgName, tarballName);
return fs.existsSync(pathCached);
}
export default function (server, server2, server3) {
describe('storage tarball cache test', () => {
// more info #131
beforeAll(function () {
return server.addPackage(PKG_GH131);
});
beforeAll(function () {
return server
.putTarball(PKG_GH131, TARBALL, getBinary())
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
beforeAll(function () {
const pkg = requirePackage(PKG_GH131);
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server
.putVersion(PKG_GH131, '0.0.1', pkg)
.status(HTTP_STATUS.CREATED)
.body_ok(/published/);
});
beforeAll(function () {
return server3.getPackage(PKG_GH131).status(HTTP_STATUS.OK);
});
beforeAll(function () {
return server3.getTarball(PKG_GH131, TARBALL).status(HTTP_STATUS.OK);
});
test('should be caching packages from uplink server1', () => {
expect(isCached(PKG_GH131, TARBALL)).toEqual(true);
});
beforeAll(function () {
return server2.addPackage(PKG_GH1312);
});
beforeAll(function () {
return server2
.putTarball(PKG_GH1312, TARBALL, getBinary())
.status(HTTP_STATUS.CREATED)
.body_ok(/.*/);
});
beforeAll(function () {
const pkg = requirePackage(PKG_GH1312);
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
return server2
.putVersion(PKG_GH1312, '0.0.1', pkg)
.status(HTTP_STATUS.CREATED)
.body_ok(/published/);
});
beforeAll(function () {
return server3.getPackage(PKG_GH1312).status(HTTP_STATUS.OK);
});
beforeAll(function () {
return server3.getTarball(PKG_GH1312, TARBALL).status(HTTP_STATUS.OK);
});
test('must not be caching packages from uplink server2', () => {
expect(isCached(PKG_GH1312, TARBALL)).toEqual(false);
});
});
}