2018-06-24 15:39:09 -05:00
|
|
|
import path from 'path';
|
2021-03-14 02:42:46 -05:00
|
|
|
import { DOMAIN_SERVERS } from '../../functional/config.functional';
|
2018-06-24 15:39:09 -05:00
|
|
|
import VerdaccioProcess from '../../lib/server_process';
|
2021-03-14 02:42:46 -05:00
|
|
|
import { VerdaccioConfig } from '../../lib/verdaccio-server';
|
2018-06-24 15:39:09 -05:00
|
|
|
import Server from '../../lib/server';
|
2021-03-14 02:42:46 -05:00
|
|
|
import { IServerBridge } from '../../types';
|
2018-06-24 15:39:09 -05:00
|
|
|
|
2019-05-19 14:37:43 -05:00
|
|
|
/**
|
2019-05-19 15:23:12 -05:00
|
|
|
* Fork a Verdaccio process with a custom configuration.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* - Fork the process within the beforeAll body.
|
|
|
|
* - Define a storage (use a specific name)
|
|
|
|
* - Define a unique port (be careful with conflicts)
|
|
|
|
* - Set a configuration
|
|
|
|
* - await / mockServer
|
|
|
|
* - call done();
|
|
|
|
*
|
|
|
|
* beforeAll(function(done) {
|
|
|
|
const store = path.join(__dirname, '../partials/store/test-profile-storage');
|
|
|
|
const mockServerPort = 55544;
|
|
|
|
rimraf(store, async () => {
|
|
|
|
const parsedConfig = parseConfigFile(parseConfigurationProfile());
|
|
|
|
const configForTest = _.assign({}, _.cloneDeep(parsedConfig), {
|
|
|
|
storage: store,
|
|
|
|
auth: {
|
|
|
|
htpasswd: {
|
|
|
|
file: './test-profile-storage/.htpasswd'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self_path: store
|
|
|
|
});
|
|
|
|
app = await endPointAPI(configForTest);
|
|
|
|
mockRegistry = await mockServer(mockServerPort).init();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
On finish the test we must close the server
|
|
|
|
|
|
|
|
afterAll(function(done) {
|
|
|
|
mockRegistry[0].stop();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
*
|
2019-05-19 14:37:43 -05:00
|
|
|
*
|
|
|
|
* @param port
|
|
|
|
* @returns {VerdaccioProcess}
|
|
|
|
*/
|
2018-06-24 15:39:09 -05:00
|
|
|
export function mockServer(port: number) {
|
|
|
|
const pathStore = path.join(__dirname, '../partials');
|
2019-05-19 14:03:45 -05:00
|
|
|
const storePath = path.join(pathStore, '/mock-store');
|
|
|
|
const configPath = path.join(pathStore, '/config-unit-mock-server-test.yaml');
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
const verdaccioConfig = new VerdaccioConfig(
|
|
|
|
storePath,
|
|
|
|
configPath,
|
|
|
|
`http://${DOMAIN_SERVERS}:${port}/`,
|
|
|
|
port
|
|
|
|
);
|
2019-05-19 14:03:45 -05:00
|
|
|
|
2018-06-24 15:39:09 -05:00
|
|
|
const server: IServerBridge = new Server(verdaccioConfig.domainPath);
|
|
|
|
|
|
|
|
return new VerdaccioProcess(verdaccioConfig, server, false, false, false);
|
|
|
|
}
|