2022-01-09 14:51:50 -05:00
|
|
|
import express from 'express';
|
|
|
|
import request from 'request';
|
|
|
|
import rimraf from 'rimraf';
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2022-01-09 14:51:50 -05:00
|
|
|
import endPointAPI from '../../../src/api/index';
|
|
|
|
import { API_ERROR } from '../../../src/lib/constants';
|
2019-07-16 01:40:01 -05:00
|
|
|
import { setup } from '../../../src/lib/logger';
|
2022-01-09 14:51:50 -05:00
|
|
|
import config from '../partials/config/index';
|
2019-07-16 01:40:01 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
setup([{ type: 'stdout', format: 'pretty', level: 'trace' }]);
|
2019-07-16 01:40:01 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
const app = express();
|
|
|
|
const server = require('http').createServer(app);
|
|
|
|
|
|
|
|
describe('basic system test', () => {
|
2017-04-19 14:15:28 -05:00
|
|
|
let port;
|
2019-07-08 02:20:16 -05:00
|
|
|
jest.setTimeout(20000);
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
beforeAll(function (done) {
|
2017-07-01 17:05:58 -05:00
|
|
|
rimraf(__dirname + '/store/test-storage', done);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
beforeAll(async function (done) {
|
2019-02-24 17:20:25 -05:00
|
|
|
app.use(await endPointAPI(config()));
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
server.listen(0, function () {
|
2017-04-19 14:15:28 -05:00
|
|
|
port = server.address().port;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
afterAll((done) => {
|
|
|
|
server.close(done);
|
|
|
|
});
|
|
|
|
|
2022-03-04 15:08:18 -05:00
|
|
|
// TODO: recieve aborted call [Error: aborted], please review
|
|
|
|
test.skip('server should respond on /', (done) => {
|
2021-03-14 02:42:46 -05:00
|
|
|
request(
|
|
|
|
{
|
2021-10-24 03:15:54 -05:00
|
|
|
url: 'http://localhost:' + port + '/',
|
|
|
|
timeout: 6000,
|
2021-03-14 02:42:46 -05:00
|
|
|
},
|
|
|
|
function (err, res, body) {
|
2021-10-24 03:15:54 -05:00
|
|
|
// TEMP: figure out why is flacky, pls remove when is stable.
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.log('server should respond on / error', err);
|
2021-03-14 02:42:46 -05:00
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(body).toMatch(/Verdaccio/);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
2022-01-09 14:31:26 -05:00
|
|
|
}, 10000);
|
2014-12-22 12:58:25 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
test('server should respond on /___not_found_package', (done) => {
|
|
|
|
request(
|
|
|
|
{
|
2021-10-24 03:15:54 -05:00
|
|
|
url: `http://localhost:${port}/___not_found_package`,
|
2021-03-14 02:42:46 -05:00
|
|
|
},
|
|
|
|
function (err, res, body) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(body).toMatch(API_ERROR.NO_PACKAGE);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
2022-01-09 14:31:26 -05:00
|
|
|
}, 10000);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|