Skip to content

Commit

Permalink
build: upgrade to jest 27 (verdaccio#2297)
Browse files Browse the repository at this point in the history
* migrate to jest 27

* test
  • Loading branch information
juanpicado authored Jun 13, 2021
1 parent 6740608 commit 73d34bf
Show file tree
Hide file tree
Showing 17 changed files with 1,641 additions and 1,490 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.2.0",
"@types/async": "3.2.5",
"@types/autocannon": "4.1.0",
"@types/autosuggest-highlight": "3.1.1",
"@types/express": "4.17.6",
"@types/http-errors": "1.8.0",
Expand All @@ -52,7 +53,6 @@
"@types/lodash": "4.14.167",
"@types/lowdb": "^1.0.9",
"@types/mime": "2.0.2",
"@types/autocannon": "4.1.0",
"@types/minimatch": "3.0.3",
"@types/node": "^14.14.7",
"@types/react": "16.14.2",
Expand All @@ -69,48 +69,48 @@
"@types/webpack-env": "1.16.0",
"@typescript-eslint/eslint-plugin": "4.13.0",
"@typescript-eslint/parser": "4.13.0",
"@verdaccio/types": "workspace:*",
"@verdaccio/ui-theme": "workspace:*",
"@verdaccio/benchmark": "workspace:*",
"@verdaccio/eslint-config": "workspace:*",
"@verdaccio/types": "workspace:*",
"@verdaccio/ui-theme": "workspace:*",
"autocannon": "7.3.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"babel-jest": "26.6.3",
"babel-jest": "27.0.2",
"babel-plugin-dynamic-import-node": "2.3.3",
"babel-plugin-emotion": "11.0.0",
"codecov": "3.8.1",
"concurrently": "^5.3.0",
"core-js": "^3.12.1",
"cross-env": "7.0.3",
"debug": "4.3.1",
"detect-secrets": "1.0.6",
"autocannon": "7.3.0",
"eslint": "7.26.0",
"eslint-config-google": "0.14.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-babel": "5.3.1",
"eslint-plugin-import": "2.23.2",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.23.2",
"eslint-plugin-react-hooks": "4.2.0",
"eslint-plugin-simple-import-sort": "7.0.0",
"eslint-plugin-verdaccio": "10.0.0",
"eslint-plugin-prettier": "3.4.0",
"fs-extra": "9.1.0",
"debug": "4.3.1",
"husky": "2.7.0",
"in-publish": "2.0.1",
"jest": "26.6.3",
"jest-environment-jsdom": "26.6.2",
"jest": "27.0.4",
"jest-environment-jsdom": "27.0.3",
"jest-environment-jsdom-global": "^2.0.4",
"jest-environment-node": "26.6.2",
"jest-environment-node": "27.0.3",
"jest-fetch-mock": "3.0.3",
"jest-junit": "11.0.1",
"kleur": "4.1.4",
"lint-staged": "8.2.1",
"nock": "12.0.3",
"nodemon": "^2.0.7",
"node-fetch": "2.6.1",
"nodemon": "^2.0.7",
"npm-run-all": "4.1.5",
"prettier": "2.3.0",
"rimraf": "3.0.2",
Expand All @@ -131,7 +131,7 @@
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
"lint": "eslint --max-warnings 48 \"**/*.{js,jsx,ts,tsx}\"",
"lint": "eslint --max-warnings 49 \"**/*.{js,jsx,ts,tsx}\"",
"test": "pnpm recursive test --filter ./packages",
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",
Expand Down
44 changes: 24 additions & 20 deletions packages/api/test/integration/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,34 @@ describe('package', () => {
app = await initializeServer('package.yaml');
});

test('should return a package', async (done) => {
test('should return a package', async () => {
await publishVersion(app, 'package.yaml', 'foo', '1.0.0');
return supertest(app)
.get('/foo')
.set('Accept', HEADERS.JSON)
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.OK)
.then((response) => {
expect(response.body.name).toEqual('foo');
done();
});
return new Promise((resolve) => {
supertest(app)
.get('/foo')
.set('Accept', HEADERS.JSON)
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.OK)
.then((response) => {
expect(response.body.name).toEqual('foo');
resolve(response);
});
});
});

test('should return a package by version', async (done) => {
test('should return a package by version', async () => {
await publishVersion(app, 'package.yaml', 'foo2', '1.0.0');
return supertest(app)
.get('/foo2/1.0.0')
.set('Accept', HEADERS.JSON)
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.OK)
.then((response) => {
expect(response.body.name).toEqual('foo2');
done();
});
return new Promise((resolve) => {
supertest(app)
.get('/foo2/1.0.0')
.set('Accept', HEADERS.JSON)
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HTTP_STATUS.OK)
.then((response) => {
expect(response.body.name).toEqual('foo2');
resolve(response);
});
});
});

// TODO: investigate the 404
Expand Down
146 changes: 77 additions & 69 deletions packages/api/test/integration/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const mockApiJWTmiddleware = jest.fn(
}
);

jest.setTimeout(50000000);

jest.mock('@verdaccio/auth', () => ({
Auth: class {
apiJWTmiddleware() {
Expand Down Expand Up @@ -86,98 +84,108 @@ describe('publish', () => {
});
});

test('should fail on publish a bad versions package', async (done) => {
test('should fail on publish a bad versions package', async () => {
const app = await initializeServer('publish.yaml');
return supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
versions: '',
})
return new Promise((resolve) => {
supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
versions: '',
})
)
)
)
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.BAD_REQUEST)
.then((response) => {
console.log('response.body', response.body);
expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
done();
});
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.BAD_REQUEST)
.then((response) => {
console.log('response.body', response.body);
expect(response.body.error).toEqual(API_ERROR.UNSUPORTED_REGISTRY_CALL);
resolve(response);
});
});
});
});

describe('publish a package', () => {
test('should publish a package', async (done) => {
test('should publish a package', async () => {
const app = await initializeServer('publish.yaml');
return publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
done();
});
return new Promise((resolve) => {
publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
resolve(response);
});
});
});

test('should publish a new package', async (done) => {
test('should publish a new package', async () => {
const pkgName = 'test';
const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
const app = await initializeServer('publish.yaml');
return supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
_attachments: null,
})
return new Promise((resolve) => {
supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
_attachments: null,
})
)
)
)
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
done();
});
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
resolve(response);
});
});
});

test('should publish a new package with no readme', async (done) => {
test('should publish a new package with no readme', async () => {
const pkgName = 'test';
const pkgMetadata = generatePackageMetadata(pkgName, '1.0.0');
const app = await initializeServer('publish.yaml');
return supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
versions: {
['1.0.0']: {
readme: null,
return new Promise((resolve) => {
supertest(app)
.put(`/${encodeURIComponent(pkgName)}`)
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
.send(
JSON.stringify(
Object.assign({}, pkgMetadata, {
versions: {
['1.0.0']: {
readme: null,
},
},
},
})
})
)
)
)
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
done();
});
.set('accept', HEADERS.GZIP)
.expect(HTTP_STATUS.CREATED)
.then((response) => {
expect(response.body.ok).toEqual(API_MESSAGE.PKG_CREATED);
resolve(response);
});
});
});
});

test('should fails on publish a duplicated package', async (done) => {
test('should fails on publish a duplicated package', async () => {
const app = await initializeServer('publish.yaml');
await publishVersion(app, 'publish.yaml', 'foo', '1.0.0');
return publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
.expect(HTTP_STATUS.CONFLICT)
.then((response) => {
console.log('response.body', response.body);
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
done();
});
return new Promise((resolve) => {
publishVersion(app, 'publish.yaml', 'foo', '1.0.0')
.expect(HTTP_STATUS.CONFLICT)
.then((response) => {
console.log('response.body', response.body);
expect(response.body.error).toEqual(API_ERROR.PACKAGE_EXIST);
resolve(response);
});
});
});

describe('unpublish a package', () => {
Expand Down
Loading

0 comments on commit 73d34bf

Please sign in to comment.