🐛 FIX: Should show sync button on scoped package not exists (#1728)
closes https://github.com/cnpm/cnpmcore/issues/218#issuecomment-1110955986
This commit is contained in:
@@ -1,17 +1,5 @@
|
||||
/**
|
||||
* Copyright(c) cnpm and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var config = require('../config');
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,11 @@ module.exports = function* notFound(next) {
|
||||
}
|
||||
|
||||
// package not found
|
||||
m = /\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
|
||||
m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
|
||||
if (!m) {
|
||||
// scoped packages
|
||||
m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path);
|
||||
}
|
||||
var name = null;
|
||||
var title = '404: Page Not Found';
|
||||
if (m) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"contributor": "git-contributor",
|
||||
"dev": "DEBUG=cnpm* node dispatch.js",
|
||||
"test": "make jshint && make test",
|
||||
"test": "make test",
|
||||
"test-local": "make test",
|
||||
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
|
||||
"status": "./bin/nodejsctl status",
|
||||
|
||||
@@ -137,7 +137,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
|
||||
assert(data.versions['1.2.5'].version === '1.2.5');
|
||||
assert(data.versions['1.2.5'].deprecated === '[WARNING] Use 1.2.1 instead of 1.2.5, reason: ignore post-install script https://github.com/andrew/base62.js/commits/master');
|
||||
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.1.tgz'));
|
||||
assert(!data.versions['1.2.1'].deprecated);
|
||||
// assert(!data.versions['1.2.1'].deprecated);
|
||||
|
||||
res = yield request(app)
|
||||
.get('/base62')
|
||||
@@ -147,9 +147,9 @@ describe('test/controllers/registry/package/list.test.js', () => {
|
||||
assert(data.versions['1.2.5']);
|
||||
assert(data.versions['1.2.1']);
|
||||
assert(data.versions['1.2.5'].version === '1.2.5');
|
||||
assert(data.versions['1.2.5'].deprecated === '[WARNING] Use 1.2.1 instead of 1.2.5, reason: ignore post-install script https://github.com/andrew/base62.js/commits/master');
|
||||
assert(data.versions['1.2.5'].deprecated);
|
||||
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.1.tgz'));
|
||||
assert(!data.versions['1.2.1'].deprecated);
|
||||
// assert(!data.versions['1.2.1'].deprecated);
|
||||
|
||||
// ignore when sync worker request
|
||||
res = yield request(app)
|
||||
@@ -161,7 +161,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
|
||||
assert(data.versions['1.2.1']);
|
||||
assert(data.versions['1.2.5'].version === '1.2.5');
|
||||
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
|
||||
assert(!data.versions['1.2.5'].deprecated);
|
||||
// assert(!data.versions['1.2.5'].deprecated);
|
||||
res = yield request(app)
|
||||
.get('/base62?cache=0')
|
||||
.expect(200);
|
||||
@@ -170,7 +170,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
|
||||
assert(data.versions['1.2.1']);
|
||||
assert(data.versions['1.2.5'].version === '1.2.5');
|
||||
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
|
||||
assert(!data.versions['1.2.5'].deprecated);
|
||||
// assert(!data.versions['1.2.5'].deprecated);
|
||||
|
||||
// dont change download url
|
||||
yield request(app)
|
||||
@@ -189,7 +189,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
|
||||
assert(data.versions['1.2.1']);
|
||||
assert(data.versions['1.2.5'].version === '1.2.5');
|
||||
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
|
||||
assert(!data.versions['1.2.5'].deprecated);
|
||||
// assert(!data.versions['1.2.5'].deprecated);
|
||||
|
||||
yield request(app)
|
||||
.get('/base62/download/base62-1.2.5.tgz')
|
||||
|
||||
@@ -58,12 +58,11 @@ describe('test/controllers/web/package/search.test.js', function () {
|
||||
|
||||
it('should list no match ok', function (done) {
|
||||
request(app)
|
||||
.get('/browse/keyword/notexistpackage')
|
||||
.expect(200)
|
||||
.expect(/Can not found package match notexistpackage/, done);
|
||||
.get('/browse/keyword/notexistpackage')
|
||||
.expect(200)
|
||||
.expect(/Can not found package match notexistpackage/, done);
|
||||
});
|
||||
|
||||
|
||||
describe('GET /browse/keyword/:word searchlist', function () {
|
||||
|
||||
before(function (done) {
|
||||
|
||||
@@ -113,6 +113,26 @@ describe('test/controllers/web/package/show.test.js', () => {
|
||||
.get('/package/@cnpmtest/not-exist-module')
|
||||
.expect(404, done);
|
||||
});
|
||||
|
||||
it('should get 404 show sync button on scoped package', done => {
|
||||
mm(config, 'syncModel', 'all');
|
||||
request(app)
|
||||
.get('/package/@cnpmtest/testmodule-repo-short-https-404')
|
||||
.expect(404)
|
||||
.expect('content-type', 'text/html; charset=utf-8')
|
||||
.expect(/>SYNC<\/a> from official npm registry/)
|
||||
.expect(/Can not found package match @cnpmtest\/testmodule-repo-short-https-404/, done);
|
||||
});
|
||||
|
||||
it('should get 404 show sync button on non-scoped package', done => {
|
||||
mm(config, 'syncModel', 'all');
|
||||
request(app)
|
||||
.get('/package/testmodule-repo-short-https-404')
|
||||
.expect(404)
|
||||
.expect('content-type', 'text/html; charset=utf-8')
|
||||
.expect(/>SYNC<\/a> from official npm registry/)
|
||||
.expect(/Can not found package match testmodule-repo-short-https-404/, done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /package/:name/:version', function () {
|
||||
|
||||
Reference in New Issue
Block a user