Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2022-08-18 18:01:06 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-08-22 21:14:50 +0300
commitd54f03132a5e8247cdd8a3c165669477e95980fb (patch)
treef84f77baf8160e0e7af54f5731d6c9983a8e1e70 /workspaces
parent897d2183d4ba1223e1084b9d574b7afa9cc9cd46 (diff)
chore: linting
In preparation for @npmcli/eslint-config@3.1.0
Diffstat (limited to 'workspaces')
-rw-r--r--workspaces/libnpmaccess/test/index.js267
-rw-r--r--workspaces/libnpmdiff/test/tarball.js33
-rw-r--r--workspaces/libnpmexec/test/run-script.js22
-rw-r--r--workspaces/libnpmorg/test/index.js62
-rw-r--r--workspaces/libnpmsearch/test/index.js140
-rw-r--r--workspaces/libnpmteam/test/index.js179
6 files changed, 275 insertions, 428 deletions
diff --git a/workspaces/libnpmaccess/test/index.js b/workspaces/libnpmaccess/test/index.js
index 7417ab562..689788d52 100644
--- a/workspaces/libnpmaccess/test/index.js
+++ b/workspaces/libnpmaccess/test/index.js
@@ -10,127 +10,96 @@ const OPTS = {
registry: REG,
}
-t.test('access public', t => {
+t.test('access public', async t => {
tnock(t, REG).post(
'/-/package/%40foo%2Fbar/access', { access: 'public' }
).reply(200)
- return access.public('@foo/bar', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.public('@foo/bar', OPTS))
})
-t.test('access public - failure', t => {
+t.test('access public - failure', async t => {
tnock(t, REG).post(
'/-/package/%40foo%2Fbar/access', { access: 'public' }
).reply(418)
- return access.public('@foo/bar', OPTS)
- .catch(err => {
- t.equal(err.statusCode, 418, 'fails with code from registry')
- })
+ await t.rejects(
+ access.public('@foo/bar', OPTS),
+ { statusCode: 418 },
+ 'fails with code from registry'
+ )
})
-t.test('access restricted', t => {
+t.test('access restricted', async t => {
tnock(t, REG).post(
'/-/package/%40foo%2Fbar/access', { access: 'restricted' }
).reply(200)
- return access.restricted('@foo/bar', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.restricted('@foo/bar', OPTS))
})
-t.test('access restricted - failure', t => {
+t.test('access restricted - failure', async t => {
tnock(t, REG).post(
'/-/package/%40foo%2Fbar/access', { access: 'restricted' }
).reply(418)
- return access.restricted('@foo/bar', OPTS)
- .catch(err => {
- t.equal(err.statusCode, 418, 'fails with code from registry')
- })
+ await t.rejects(
+ access.restricted('@foo/bar', OPTS),
+ { statusCode: 418 },
+ 'fails with code from registry')
})
-t.test('access 2fa-required', t => {
+t.test('access 2fa-required', async t => {
tnock(t, REG).post('/-/package/%40foo%2Fbar/access', {
publish_requires_tfa: true,
}).reply(200, { ok: true })
- return access.tfaRequired('@foo/bar', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.tfaRequired('@foo/bar', OPTS))
})
-t.test('access 2fa-not-required', t => {
+t.test('access 2fa-not-required', async t => {
tnock(t, REG).post('/-/package/%40foo%2Fbar/access', {
publish_requires_tfa: false,
}).reply(200, { ok: true })
- return access.tfaNotRequired('@foo/bar', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.tfaNotRequired('@foo/bar', OPTS))
})
-t.test('access grant basic read-write', t => {
+t.test('access grant basic read-write', async t => {
tnock(t, REG).put('/-/team/myorg/myteam/package', {
package: '@foo/bar',
permissions: 'read-write',
}).reply(201)
- return access.grant(
- '@foo/bar', 'myorg:myteam', 'read-write', OPTS
- ).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.grant('@foo/bar', 'myorg:myteam', 'read-write', OPTS))
})
-t.test('access grant basic read-only', t => {
+t.test('access grant basic read-only', async t => {
tnock(t, REG).put('/-/team/myorg/myteam/package', {
package: '@foo/bar',
permissions: 'read-only',
}).reply(201)
- return access.grant(
- '@foo/bar', 'myorg:myteam', 'read-only', OPTS
- ).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.grant('@foo/bar', 'myorg:myteam', 'read-only', OPTS))
})
-t.test('access grant bad perm', t => {
- return access.grant(
- '@foo/bar', 'myorg:myteam', 'unknown', OPTS
- ).then(ret => {
- throw new Error('should not have succeeded')
- }, err => {
- t.match(
- err.message,
- /must be.*read-write.*read-only/,
- 'only read-write and read-only are accepted'
- )
- })
+t.test('access grant bad perm', async t => {
+ await t.rejects(
+ access.grant('@foo/bar', 'myorg:myteam', 'unknown', OPTS),
+ { message: /must be.*read-write.*read-only/ },
+ 'only read-write and read-only are accepted'
+ )
})
-t.test('access grant no entity', t => {
- return access.grant(
- '@foo/bar', undefined, 'read-write', OPTS
- ).then(ret => {
- throw new Error('should not have succeeded')
- }, err => {
- t.match(
- err.message,
- /Expected string/,
- 'passing undefined entity gives useful error'
- )
- })
+t.test('access grant no entity', async t => {
+ await t.rejects(
+ access.grant('@foo/bar', undefined, 'read-write', OPTS),
+ { message: /Expected string/ },
+ 'passing undefined entity gives useful error'
+ )
})
-t.test('access grant basic unscoped', t => {
+t.test('access grant basic unscoped', async t => {
tnock(t, REG).put('/-/team/myorg/myteam/package', {
package: 'bar',
permissions: 'read-write',
}).reply(201)
- return access.grant(
- 'bar', 'myorg:myteam', 'read-write', OPTS
- ).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.grant('bar', 'myorg:myteam', 'read-write', OPTS))
})
-t.test('access grant no opts passed', t => {
+t.test('access grant no opts passed', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url
tnock(t, 'https://registry.npmjs.org')
@@ -139,31 +108,24 @@ t.test('access grant no opts passed', t => {
permissions: 'read-write',
})
.reply(201)
- return access.grant('bar', 'myorg:myteam', 'read-write')
- .then(ret => {
- t.equal(ret, true, 'request succeeded')
- })
+ await t.resolves(access.grant('bar', 'myorg:myteam', 'read-write'))
})
-t.test('access revoke basic', t => {
+t.test('access revoke basic', async t => {
tnock(t, REG).delete('/-/team/myorg/myteam/package', {
package: '@foo/bar',
}).reply(200)
- return access.revoke('@foo/bar', 'myorg:myteam', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.revoke('@foo/bar', 'myorg:myteam', OPTS))
})
-t.test('access revoke basic unscoped', t => {
+t.test('access revoke basic unscoped', async t => {
tnock(t, REG).delete('/-/team/myorg/myteam/package', {
package: 'bar',
}).reply(200, { accessChanged: true })
- return access.revoke('bar', 'myorg:myteam', OPTS).then(ret => {
- t.same(ret, true, 'request succeeded')
- })
+ await t.resolves(access.revoke('bar', 'myorg:myteam', OPTS))
})
-t.test('access revoke no opts passed', t => {
+t.test('access revoke no opts passed', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url
tnock(t, 'https://registry.npmjs.org')
@@ -171,13 +133,10 @@ t.test('access revoke no opts passed', t => {
package: 'bar',
})
.reply(201)
- return access.revoke('bar', 'myorg:myteam')
- .then(ret => {
- t.equal(ret, true, 'request succeeded')
- })
+ await t.resolves(access.revoke('bar', 'myorg:myteam'))
})
-t.test('ls-packages on team', t => {
+t.test('ls-packages on team', async t => {
const serverPackages = {
'@foo/bar': 'write',
'@foo/util': 'read',
@@ -191,12 +150,11 @@ t.test('ls-packages on team', t => {
tnock(t, REG).get(
'/-/team/myorg/myteam/package?format=cli'
).reply(200, serverPackages)
- return access.lsPackages('myorg:myteam', OPTS).then(data => {
- t.same(data, clientPackages, 'got client package info')
- })
+ const data = await access.lsPackages('myorg:myteam', OPTS)
+ t.same(data, clientPackages, 'got client package info')
})
-t.test('ls-packages on org', t => {
+t.test('ls-packages on org', async t => {
const serverPackages = {
'@foo/bar': 'write',
'@foo/util': 'read',
@@ -210,12 +168,11 @@ t.test('ls-packages on org', t => {
tnock(t, REG).get(
'/-/org/myorg/package?format=cli'
).reply(200, serverPackages)
- return access.lsPackages('myorg', OPTS).then(data => {
- t.same(data, clientPackages, 'got client package info')
- })
+ const data = await access.lsPackages('myorg', OPTS)
+ t.same(data, clientPackages, 'got client package info')
})
-t.test('ls-packages on user', t => {
+t.test('ls-packages on user', async t => {
const serverPackages = {
'@foo/bar': 'write',
'@foo/util': 'read',
@@ -229,43 +186,39 @@ t.test('ls-packages on user', t => {
const srv = tnock(t, REG)
srv.get('/-/org/myuser/package?format=cli').reply(404, { error: 'not found' })
srv.get('/-/user/myuser/package?format=cli').reply(200, serverPackages)
- return access.lsPackages('myuser', OPTS).then(data => {
- t.same(data, clientPackages, 'got client package info')
- })
+ const data = await access.lsPackages('myuser', OPTS)
+ t.same(data, clientPackages, 'got client package info')
})
-t.test('ls-packages error on team', t => {
+t.test('ls-packages error on team', async t => {
tnock(t, REG).get('/-/team/myorg/myteam/package?format=cli').reply(404)
- return access.lsPackages('myorg:myteam', OPTS).then(
- () => {
- throw new Error('should not have succeeded')
- },
- err => t.equal(err.code, 'E404', 'spit out 404 directly if team provided')
+ await t.rejects(
+ access.lsPackages('myorg:myteam', OPTS),
+ { code: 'E404' },
+ 'spit out 404 directly if team provided'
)
})
-t.test('ls-packages error on user', t => {
+t.test('ls-packages error on user', async t => {
const srv = tnock(t, REG)
srv.get('/-/org/myuser/package?format=cli').reply(404, { error: 'not found' })
srv.get('/-/user/myuser/package?format=cli').reply(404, { error: 'not found' })
- return access.lsPackages('myuser', OPTS).then(
- () => {
- throw new Error('should not have succeeded')
- },
- err => t.equal(err.code, 'E404', 'spit out 404 if both reqs fail')
+ await t.rejects(
+ access.lsPackages('myuser', OPTS),
+ { code: 'E404' },
+ 'spit out 404 if both reqs fail'
)
})
-t.test('ls-packages bad response', t => {
+t.test('ls-packages bad response', async t => {
tnock(t, REG).get(
'/-/team/myorg/myteam/package?format=cli'
).reply(200, JSON.stringify(null))
- return access.lsPackages('myorg:myteam', OPTS).then(data => {
- t.same(data, null, 'succeeds with null')
- })
+ const data = await access.lsPackages('myorg:myteam', OPTS)
+ t.same(data, null, 'succeeds with null')
})
-t.test('ls-packages stream', t => {
+t.test('ls-packages stream', async t => {
const serverPackages = {
'@foo/bar': 'write',
'@foo/util': 'read',
@@ -279,14 +232,11 @@ t.test('ls-packages stream', t => {
tnock(t, REG).get(
'/-/team/myorg/myteam/package?format=cli'
).reply(200, serverPackages)
- return access.lsPackages.stream('myorg:myteam', OPTS)
- .collect()
- .then(data => {
- t.same(data, clientPackages, 'got streamed client package info')
- })
+ const data = await access.lsPackages.stream('myorg:myteam', OPTS).collect()
+ t.same(data, clientPackages, 'got streamed client package info')
})
-t.test('ls-packages stream no opts', t => {
+t.test('ls-packages stream no opts', async t => {
const serverPackages = {
'@foo/bar': 'write',
'@foo/util': 'read',
@@ -302,14 +252,11 @@ t.test('ls-packages stream no opts', t => {
tnock(t, 'https://registry.npmjs.org')
.get('/-/team/myorg/myteam/package?format=cli')
.reply(200, serverPackages)
- return access.lsPackages.stream('myorg:myteam')
- .collect()
- .then(data => {
- t.same(data, clientPackages, 'got streamed client package info')
- })
+ const data = await access.lsPackages.stream('myorg:myteam').collect()
+ t.same(data, clientPackages, 'got streamed client package info')
})
-t.test('ls-collaborators', t => {
+t.test('ls-collaborators', async t => {
const serverCollaborators = {
'myorg:myteam': 'write',
'myorg:anotherteam': 'read',
@@ -323,12 +270,11 @@ t.test('ls-collaborators', t => {
tnock(t, REG).get(
'/-/package/%40foo%2Fbar/collaborators?format=cli'
).reply(200, serverCollaborators)
- return access.lsCollaborators('@foo/bar', OPTS).then(data => {
- t.same(data, clientCollaborators, 'got collaborators')
- })
+ const data = await access.lsCollaborators('@foo/bar', OPTS)
+ t.same(data, clientCollaborators, 'got collaborators')
})
-t.test('ls-collaborators stream', t => {
+t.test('ls-collaborators stream', async t => {
const serverCollaborators = {
'myorg:myteam': 'write',
'myorg:anotherteam': 'read',
@@ -342,14 +288,11 @@ t.test('ls-collaborators stream', t => {
tnock(t, REG).get(
'/-/package/%40foo%2Fbar/collaborators?format=cli'
).reply(200, serverCollaborators)
- return access.lsCollaborators.stream('@foo/bar', OPTS)
- .collect()
- .then(data => {
- t.same(data, clientCollaborators, 'got collaborators')
- })
+ const data = await access.lsCollaborators.stream('@foo/bar', OPTS).collect()
+ t.same(data, clientCollaborators, 'got collaborators')
})
-t.test('ls-collaborators w/scope', t => {
+t.test('ls-collaborators w/scope', async t => {
const serverCollaborators = {
'myorg:myteam': 'write',
'myorg:anotherteam': 'read',
@@ -363,12 +306,11 @@ t.test('ls-collaborators w/scope', t => {
tnock(t, REG).get(
'/-/package/%40foo%2Fbar/collaborators?format=cli&user=zkat'
).reply(200, serverCollaborators)
- return access.lsCollaborators('@foo/bar', 'zkat', OPTS).then(data => {
- t.same(data, clientCollaborators, 'got collaborators')
- })
+ const data = await access.lsCollaborators('@foo/bar', 'zkat', OPTS)
+ t.same(data, clientCollaborators, 'got collaborators')
})
-t.test('ls-collaborators w/o scope', t => {
+t.test('ls-collaborators w/o scope', async t => {
const serverCollaborators = {
'myorg:myteam': 'write',
'myorg:anotherteam': 'read',
@@ -382,36 +324,33 @@ t.test('ls-collaborators w/o scope', t => {
tnock(t, REG).get(
'/-/package/bar/collaborators?format=cli&user=zkat'
).reply(200, serverCollaborators)
- return access.lsCollaborators('bar', 'zkat', OPTS).then(data => {
- t.same(data, clientCollaborators, 'got collaborators')
- })
+ const data = await access.lsCollaborators('bar', 'zkat', OPTS)
+ t.same(data, clientCollaborators, 'got collaborators')
})
-t.test('ls-collaborators bad response', t => {
+t.test('ls-collaborators bad response', async t => {
tnock(t, REG).get(
'/-/package/%40foo%2Fbar/collaborators?format=cli'
).reply(200, JSON.stringify(null))
- return access.lsCollaborators('@foo/bar', null, OPTS).then(data => {
- t.same(data, null, 'succeeds with null')
- })
+ const data = await access.lsCollaborators('@foo/bar', null, OPTS)
+ t.same(data, null, 'succeeds with null')
})
-t.test('error on non-registry specs', t => {
- const resolve = () => {
- throw new Error('should not succeed')
- }
- const reject = err => t.match(
- err.message, /spec.*must be a registry spec/, 'registry spec required'
- )
- return Promise.all([
- access.public('githubusername/reponame').then(resolve, reject),
- access.restricted('foo/bar').then(resolve, reject),
- access.grant('foo/bar', 'myorg', 'myteam', 'read-only').then(resolve, reject),
- access.revoke('foo/bar', 'myorg', 'myteam').then(resolve, reject),
- access.lsCollaborators('foo/bar').then(resolve, reject),
- access.tfaRequired('foo/bar').then(resolve, reject),
- access.tfaNotRequired('foo/bar').then(resolve, reject),
- ])
+t.test('error on non-registry specs', async t => {
+ await t.rejects(access.public('githubusername/reponame'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.restricted('foo/bar'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.grant('foo/bar', 'myorg', 'myteam', 'read-only'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.revoke('foo/bar', 'myorg', 'myteam'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.lsCollaborators('foo/bar'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.tfaRequired('foo/bar'),
+ /spec.*must be a registry spec/, 'registry spec required')
+ await t.rejects(access.tfaNotRequired('foo/bar'),
+ /spec.*must be a registry spec/, 'registry spec required')
})
t.test('edit', t => {
diff --git a/workspaces/libnpmdiff/test/tarball.js b/workspaces/libnpmdiff/test/tarball.js
index b0a507c84..cb6155628 100644
--- a/workspaces/libnpmdiff/test/tarball.js
+++ b/workspaces/libnpmdiff/test/tarball.js
@@ -11,7 +11,7 @@ const tarball = require('../lib/tarball.js')
const json = (obj) => `${JSON.stringify(obj, null, 2)}\n`
-t.test('returns a tarball from node_modules', t => {
+t.test('returns a tarball from node_modules', async t => {
t.plan(2)
const path = t.testdir({
@@ -33,22 +33,21 @@ t.test('returns a tarball from node_modules', t => {
process.chdir(_cwd)
})
- tarball({ bin: { a: 'index.js' }, _resolved: resolve(path, 'node_modules/a') }, { where: path })
- .then(res => {
- tar.list({
- filter: p => {
- t.match(
- p,
- /package.json|index.js/,
- 'should return tarball with expected files'
- )
- },
- })
- .on('error', e => {
- throw e
- })
- .end(res)
- })
+ const res = await tarball(
+ { bin: { a: 'index.js' }, _resolved: resolve(path, 'node_modules/a') },
+ { where: path }
+ )
+ tar.list({
+ filter: p => {
+ t.match(
+ p,
+ /package.json|index.js/,
+ 'should return tarball with expected files'
+ )
+ },
+ }).on('error', e => {
+ throw e
+ }).end(res)
})
t.test('node_modules folder within a linked dir', async t => {
diff --git a/workspaces/libnpmexec/test/run-script.js b/workspaces/libnpmexec/test/run-script.js
index 9e0db1367..40b31ebdf 100644
--- a/workspaces/libnpmexec/test/run-script.js
+++ b/workspaces/libnpmexec/test/run-script.js
@@ -55,7 +55,7 @@ t.test('no package.json', t => {
runScript(baseOpts)
})
-t.test('colorized interactive mode msg', t => {
+t.test('colorized interactive mode msg', async t => {
t.plan(2)
const runScript = t.mock('../lib/run-script.js', {
@@ -67,7 +67,7 @@ t.test('colorized interactive mode msg', t => {
})
const OUTPUT = []
- runScript({
+ await runScript({
...baseOpts,
output: msg => {
OUTPUT.push(msg)
@@ -75,15 +75,10 @@ t.test('colorized interactive mode msg', t => {
runPath: '/foo/',
color: true,
})
- .then(() => {
- t.matchSnapshot(OUTPUT.join('\n'), 'should print colorized output')
- })
- .catch(err => {
- throw err
- })
+ t.matchSnapshot(OUTPUT.join('\n'), 'should print colorized output')
})
-t.test('no color interactive mode msg', t => {
+t.test('no color interactive mode msg', async t => {
t.plan(2)
const runScript = t.mock('../lib/run-script.js', {
@@ -95,19 +90,14 @@ t.test('no color interactive mode msg', t => {
})
const OUTPUT = []
- runScript({
+ await runScript({
...baseOpts,
output: msg => {
OUTPUT.push(msg)
},
runPath: '/foo/',
})
- .then(() => {
- t.matchSnapshot(OUTPUT.join('\n'), 'should print non-colorized output')
- })
- .catch(err => {
- throw err
- })
+ t.matchSnapshot(OUTPUT.join('\n'), 'should print non-colorized output')
})
t.test('no tty', t => {
diff --git a/workspaces/libnpmorg/test/index.js b/workspaces/libnpmorg/test/index.js
index ecdda07c0..bbe4ff4fc 100644
--- a/workspaces/libnpmorg/test/index.js
+++ b/workspaces/libnpmorg/test/index.js
@@ -11,7 +11,7 @@ const OPTS = {
}
const REG = 'https://registry.npmjs.org/'
-test('set', t => {
+test('set', async t => {
const memDeets = {
org: {
name: 'myorg',
@@ -27,13 +27,11 @@ test('set', t => {
})
.reply(201, memDeets)
- return org.set('myorg', 'myuser', 'admin', OPTS)
- .then(res => {
- t.same(res, memDeets, 'got a membership details object back')
- })
+ const res = await org.set('myorg', 'myuser', 'admin', OPTS)
+ t.same(res, memDeets, 'got a membership details object back')
})
-test('optional role for set', t => {
+test('optional role for set', async t => {
const memDeets = {
org: {
name: 'myorg',
@@ -45,57 +43,48 @@ test('optional role for set', t => {
tnock(t, OPTS.registry).put('/-/org/myorg/user', {
user: 'myuser',
}).reply(201, memDeets)
- return org.set('myorg', 'myuser', OPTS).then(res => {
- t.same(res, memDeets, 'got a membership details object back')
- })
+ const res = await org.set('myorg', 'myuser', OPTS)
+ t.same(res, memDeets, 'got a membership details object back')
})
-test('rm with no options', t => {
+test('rm with no options', async t => {
tnock(t, REG).delete('/-/org/myorg/user', {
user: 'myuser',
}).reply(204)
- return org.rm('myorg', 'myuser').then(() => {
- t.ok(true, 'request succeeded')
- })
+ await t.resolves(org.rm('myorg', 'myuser'))
})
-test('rm', t => {
+test('rm', async t => {
tnock(t, OPTS.registry).delete('/-/org/myorg/user', {
user: 'myuser',
}).reply(204)
- return org.rm('myorg', 'myuser', OPTS)
- .then(ret => {
- t.equal(ret, null, 'null return value')
- t.ok(true, 'request succeeded')
- })
+ const ret = await org.rm('myorg', 'myuser', OPTS)
+ t.equal(ret, null, 'null return value')
})
-test('ls with no options', t => {
+test('ls with no options', async t => {
const roster = {
zkat: 'developer',
iarna: 'admin',
isaacs: 'owner',
}
tnock(t, REG).get('/-/org/myorg/user').reply(200, roster)
- return org.ls('myorg').then(res => {
- t.same(res, roster, 'got back a roster')
- })
+ const res = await org.ls('myorg')
+ t.same(res, roster, 'got back a roster')
})
-test('ls', t => {
+test('ls', async t => {
const roster = {
zkat: 'developer',
iarna: 'admin',
isaacs: 'owner',
}
tnock(t, OPTS.registry).get('/-/org/myorg/user').reply(200, roster)
- return org.ls('myorg', OPTS).then(res => {
- t.same(res, roster, 'got back a roster')
- })
+ const res = await org.ls('myorg', OPTS)
+ t.same(res, roster, 'got back a roster')
})
-test('ls stream with no options', t => {
- t.plan(2)
+test('ls stream with no options', async t => {
const roster = {
zkat: 'developer',
iarna: 'admin',
@@ -105,14 +94,11 @@ test('ls stream with no options', t => {
tnock(t, REG).get('/-/org/myorg/user').reply(200, roster)
const result = org.ls.stream('myorg')
t.ok(Minipass.isStream(result), 'returns a stream')
- return result.collect()
- .then(res => {
- t.same(res, rosterArr, 'got back a roster, in entries format')
- })
+ const res = await result.collect()
+ t.same(res, rosterArr, 'got back a roster, in entries format')
})
-test('ls stream', t => {
- t.plan(2)
+test('ls stream', async t => {
const roster = {
zkat: 'developer',
iarna: 'admin',
@@ -122,8 +108,6 @@ test('ls stream', t => {
tnock(t, OPTS.registry).get('/-/org/myorg/user').reply(200, roster)
const result = org.ls.stream('myorg', OPTS)
t.ok(Minipass.isStream(result), 'returns a stream')
- return result.collect()
- .then(res => {
- t.same(res, rosterArr, 'got back a roster, in entries format')
- })
+ const res = await result.collect()
+ t.same(res, rosterArr, 'got back a roster, in entries format')
})
diff --git a/workspaces/libnpmsearch/test/index.js b/workspaces/libnpmsearch/test/index.js
index 8512ecb0f..dd54949da 100644
--- a/workspaces/libnpmsearch/test/index.js
+++ b/workspaces/libnpmsearch/test/index.js
@@ -12,7 +12,7 @@ const REG = OPTS.registry
const NPM_REG = 'https://registry.npmjs.org/'
const search = require('../lib/index.js')
-test('basic test no options', t => {
+test('basic test no options', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -27,18 +27,17 @@ test('basic test no options', t => {
{ package: { name: 'foo', version: '2.0.0' } },
],
})
- return search('oo').then(results => {
- t.match(results, [{
- name: 'cool',
- version: '1.0.0',
- }, {
- name: 'foo',
- version: '2.0.0',
- }], 'got back an array of search results')
- })
+ const results = await search('oo')
+ t.match(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ }, {
+ name: 'foo',
+ version: '2.0.0',
+ }], 'got back an array of search results')
})
-test('basic test', t => {
+test('basic test', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -53,18 +52,17 @@ test('basic test', t => {
{ package: { name: 'foo', version: '2.0.0' } },
],
})
- return search('oo', OPTS).then(results => {
- t.match(results, [{
- name: 'cool',
- version: '1.0.0',
- }, {
- name: 'foo',
- version: '2.0.0',
- }], 'got back an array of search results')
- })
+ const results = await search('oo', OPTS)
+ t.match(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ }, {
+ name: 'foo',
+ version: '2.0.0',
+ }], 'got back an array of search results')
})
-test('basic test supports nested options', t => {
+test('basic test supports nested options', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -82,18 +80,17 @@ test('basic test supports nested options', t => {
// this test is to ensure we don't break the nested opts parameter
// that the cli supplies when a user passes --searchopts=
- return search('oo', { ...OPTS, opts: { from: 1 } }).then(results => {
- t.match(results, [{
- name: 'cool',
- version: '1.0.0',
- }, {
- name: 'foo',
- version: '2.0.0',
- }], 'got back an array of search results')
- })
+ const results = await search('oo', { ...OPTS, opts: { from: 1 } })
+ t.match(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ }, {
+ name: 'foo',
+ version: '2.0.0',
+ }], 'got back an array of search results')
})
-test('search.stream', t => {
+test('search.stream', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -108,18 +105,17 @@ test('search.stream', t => {
{ package: { name: 'foo', version: '2.0.0' } },
],
})
- return search.stream('oo', OPTS).collect().then(results => {
- t.match(results, [{
- name: 'cool',
- version: '1.0.0',
- }, {
- name: 'foo',
- version: '2.0.0',
- }], 'has a stream-based API function with identical results')
- })
+ const results = await search.stream('oo', OPTS).collect()
+ t.match(results, [{
+ name: 'cool',
+ version: '1.0.0',
+ }, {
+ name: 'foo',
+ version: '2.0.0',
+ }], 'has a stream-based API function with identical results')
})
-test('accepts a limit option', t => {
+test('accepts a limit option', async t => {
const query = qs.stringify({
text: 'oo',
size: 3,
@@ -136,12 +132,11 @@ test('accepts a limit option', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', { ...OPTS, limit: 3 }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
- })
+ const results = await search('oo', { ...OPTS, limit: 3 })
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('accepts a from option', t => {
+test('accepts a from option', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -158,12 +153,11 @@ test('accepts a from option', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', { ...OPTS, from: 1 }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
- })
+ const results = await search('oo', { ...OPTS, from: 1 })
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('accepts quality/mainenance/popularity options', t => {
+test('accepts quality/mainenance/popularity options', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -180,17 +174,16 @@ test('accepts quality/mainenance/popularity options', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', {
+ const results = await search('oo', {
...OPTS,
quality: 1,
popularity: 2,
maintenance: 3,
- }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
})
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('sortBy: quality', t => {
+test('sortBy: quality', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -207,15 +200,14 @@ test('sortBy: quality', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', {
+ const results = await search('oo', {
...OPTS,
sortBy: 'quality',
- }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
})
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('sortBy: popularity', t => {
+test('sortBy: popularity', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -232,15 +224,14 @@ test('sortBy: popularity', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', {
+ const results = await search('oo', {
...OPTS,
sortBy: 'popularity',
- }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
})
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('sortBy: maintenance', t => {
+test('sortBy: maintenance', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -257,15 +248,14 @@ test('sortBy: maintenance', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', {
+ const results = await search('oo', {
...OPTS,
sortBy: 'maintenance',
- }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
})
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('sortBy: optimal', t => {
+test('sortBy: optimal', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -282,15 +272,14 @@ test('sortBy: optimal', t => {
{ package: { name: 'cool', version: '1.0.0' } },
],
})
- return search('oo', {
+ const results = await search('oo', {
...OPTS,
sortBy: 'optimal',
- }).then(results => {
- t.equal(results.length, 4, 'returns more results if endpoint does so')
})
+ t.equal(results.length, 4, 'returns more results if endpoint does so')
})
-test('detailed format', t => {
+test('detailed format', async t => {
const query = qs.stringify({
text: 'oo',
size: 20,
@@ -328,16 +317,15 @@ test('detailed format', t => {
tnock(t, REG).get(`/-/v1/search?${query}`).once().reply(200, {
objects: results,
})
- return search('oo', {
+ const res = await search('oo', {
...OPTS,
sortBy: 'maintenance',
detailed: true,
- }).then(res => {
- t.same(res, results, 'return full-format results with opts.detailed')
})
+ t.same(res, results, 'return full-format results with opts.detailed')
})
-test('space-separates and URI-encodes multiple search params', t => {
+test('space-separates and URI-encodes multiple search params', async t => {
const query = qs.stringify({
text: 'foo bar:baz quux?=',
size: 1,
@@ -348,13 +336,11 @@ test('space-separates and URI-encodes multiple search params', t => {
}).replace(/%20/g, '+')
tnock(t, REG).get(`/-/v1/search?${query}`).reply(200, { objects: [] })
- return search(['foo', 'bar:baz', 'quux?='], {
+ await t.resolves(search(['foo', 'bar:baz', 'quux?='], {
...OPTS,
limit: 1,
quality: 1,
popularity: 2,
maintenance: 3,
- }).then(
- () => t.ok(true, 'sent parameters correctly urlencoded')
- )
+ }))
})
diff --git a/workspaces/libnpmteam/test/index.js b/workspaces/libnpmteam/test/index.js
index 6e0b92976..fd02666e0 100644
--- a/workspaces/libnpmteam/test/index.js
+++ b/workspaces/libnpmteam/test/index.js
@@ -10,249 +10,198 @@ const OPTS = {
registry: REG,
}
-test('create', t => {
+test('create', async t => {
tnock(t, REG).put(
'/-/org/foo/team', { name: 'cli' }
).reply(201, { name: 'cli' })
- return team.create('@foo:cli', OPTS).then(ret => {
- t.same(ret, { name: 'cli' }, 'request succeeded')
- })
+ const ret = await team.create('@foo:cli', OPTS)
+ t.same(ret, { name: 'cli' }, 'request succeeded')
})
-test('create - no options', t => {
+test('create - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.put('/-/org/foo/team', { name: 'cli' })
.reply(201, { name: 'cli' })
- return team.create('@foo:cli')
- .then(ret => {
- t.same(ret, { name: 'cli' })
- })
+ const ret = await team.create('@foo:cli')
+ t.same(ret, { name: 'cli' })
})
-test('create bad entity name', t => {
- return team.create('go away', OPTS).then(
- () => {
- throw new Error('should not succeed')
- },
- err => {
- t.ok(err, 'error on bad entity name')
- }
- )
+test('create bad entity name', async t => {
+ await t.rejects(team.create('go away', OPTS))
})
-test('create empty entity', t => {
- return team.create(undefined, OPTS).then(
- () => {
- throw new Error('should not succeed')
- },
- err => {
- t.ok(err, 'error on bad entity name')
- }
- )
+test('create empty entity', async t => {
+ await t.rejects(team.create(undefined, OPTS))
})
-test('create w/ description', t => {
+test('create w/ description', async t => {
tnock(t, REG).put('/-/org/foo/team', {
name: 'cli',
description: 'just some cool folx',
}).reply(201, { name: 'cli' })
- return team.create('@foo:cli', {
+ const ret = await team.create('@foo:cli', {
...OPTS,
description: 'just some cool folx',
- }).then(ret => {
- t.same(ret, { name: 'cli' }, 'no desc in return')
})
+ t.same(ret, { name: 'cli' }, 'no desc in return')
})
-test('destroy', t => {
+test('destroy', async t => {
tnock(t, REG).delete(
'/-/team/foo/cli'
).reply(204, {})
- return team.destroy('@foo:cli', OPTS).then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.destroy('@foo:cli', OPTS)
+ t.same(ret, {}, 'request succeeded')
})
-test('destroy - no options', t => {
+test('destroy - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.delete('/-/team/foo/cli')
.reply(204, {})
- return team.destroy('@foo:cli').then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.destroy('@foo:cli')
+ t.same(ret, {}, 'request succeeded')
})
-test('add', t => {
+test('add', async t => {
tnock(t, REG).put(
'/-/team/foo/cli/user', { user: 'zkat' }
).reply(201, {})
- return team.add('zkat', '@foo:cli', OPTS).then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.add('zkat', '@foo:cli', OPTS)
+ t.same(ret, {}, 'request succeeded')
})
-test('add - no options', t => {
+test('add - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.put('/-/team/foo/cli/user', { user: 'zkat' })
.reply(201, {})
- return team.add('zkat', '@foo:cli').then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.add('zkat', '@foo:cli')
+ t.same(ret, {}, 'request succeeded')
})
-test('rm', t => {
+test('rm', async t => {
tnock(t, REG).delete(
'/-/team/foo/cli/user', { user: 'zkat' }
).reply(204, {})
- return team.rm('zkat', '@foo:cli', OPTS).then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.rm('zkat', '@foo:cli', OPTS)
+ t.same(ret, {}, 'request succeeded')
})
-test('rm - no options', t => {
+test('rm - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.delete('/-/team/foo/cli/user', { user: 'zkat' })
.reply(204, {})
- return team.rm('zkat', '@foo:cli').then(ret => {
- t.same(ret, {}, 'request succeeded')
- })
+ const ret = await team.rm('zkat', '@foo:cli')
+ t.same(ret, {}, 'request succeeded')
})
-test('lsTeams', t => {
+test('lsTeams', async t => {
tnock(t, REG).get(
'/-/org/foo/team?format=cli'
).reply(200, ['foo:bar', 'foo:cli'])
- return team.lsTeams('foo', OPTS).then(ret => {
- t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
- })
+ const ret = await team.lsTeams('foo', OPTS)
+ t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
})
-test('lsTeams - no options', t => {
+test('lsTeams - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.get('/-/org/foo/team?format=cli')
.reply(200, ['foo:bar', 'foo:cli'])
- return team.lsTeams('foo').then(ret => {
- t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
- })
+ const ret = await team.lsTeams('foo')
+ t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
})
-test('lsTeams error', t => {
+test('lsTeams error', async t => {
tnock(t, REG).get(
'/-/org/foo/team?format=cli'
).reply(500)
- return team.lsTeams('foo', OPTS).then(
- () => {
- throw new Error('should not succeed')
- },
- err => {
- t.equal(err.code, 'E500', 'got error code')
- }
+ await t.rejects(
+ team.lsTeams('foo', OPTS),
+ { code: 'E500' }
)
})
-test('lsTeams.stream', t => {
+test('lsTeams.stream', async t => {
tnock(t, REG).get(
'/-/org/foo/team?format=cli'
).reply(200, ['foo:bar', 'foo:cli'])
- return team.lsTeams.stream('foo', OPTS)
- .collect()
- .then(ret => {
- t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
- })
+ const ret = await team.lsTeams.stream('foo', OPTS).collect()
+ t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
})
-test('lsTeams.stream - no options', t => {
+test('lsTeams.stream - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.get('/-/org/foo/team?format=cli')
.reply(200, ['foo:bar', 'foo:cli'])
- return team.lsTeams.stream('foo')
- .collect()
- .then(ret => {
- t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
- })
+ const ret = await team.lsTeams.stream('foo').collect()
+ t.same(ret, ['foo:bar', 'foo:cli'], 'got teams')
})
-test('lsUsers', t => {
+test('lsUsers', async t => {
tnock(t, REG).get(
'/-/team/foo/cli/user?format=cli'
).reply(500)
- return team.lsUsers('@foo:cli', OPTS).then(
- () => {
- throw new Error('should not succeed')
- },
- err => {
- t.equal(err.code, 'E500', 'got error code')
- }
+ await t.rejects(
+ team.lsUsers('@foo:cli', OPTS),
+ { code: 'E500' }
)
})
-test('lsUsers - no options', t => {
+test('lsUsers - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.get('/-/team/foo/cli/user?format=cli')
.reply(500)
- return team.lsUsers('@foo:cli').then(
- () => {
- throw new Error('should not succeed')
- },
- err => {
- t.equal(err.code, 'E500', 'got error code')
- }
+ await t.rejects(
+ team.lsUsers('@foo:cli'),
+ { code: 'E500' }
)
})
-test('lsUsers error', t => {
+test('lsUsers error', async t => {
tnock(t, REG).get(
'/-/team/foo/cli/user?format=cli'
).reply(200, ['iarna', 'zkat'])
- return team.lsUsers('@foo:cli', OPTS).then(ret => {
- t.same(ret, ['iarna', 'zkat'], 'got team members')
- })
+ const ret = await team.lsUsers('@foo:cli', OPTS)
+ t.same(ret, ['iarna', 'zkat'], 'got team members')
})
-test('lsUsers.stream', t => {
+test('lsUsers.stream', async t => {
tnock(t, REG).get(
'/-/team/foo/cli/user?format=cli'
).reply(200, ['iarna', 'zkat'])
- return team.lsUsers.stream('@foo:cli', OPTS)
- .collect()
- .then(ret => {
- t.same(ret, ['iarna', 'zkat'], 'got team members')
- })
+ const ret = await team.lsUsers.stream('@foo:cli', OPTS).collect()
+ t.same(ret, ['iarna', 'zkat'], 'got team members')
})
-test('lsUsers.stream - no options', t => {
+test('lsUsers.stream - no options', async t => {
// NOTE: mocking real url, because no opts variable means `registry` value
// will be defauled to real registry url in `npm-registry-fetch`
tnock(t, 'https://registry.npmjs.org')
.get('/-/team/foo/cli/user?format=cli')
.reply(200, ['iarna', 'zkat'])
- return team.lsUsers.stream('@foo:cli')
- .collect()
- .then(ret => {
- t.same(ret, ['iarna', 'zkat'], 'got team members')
- })
+ const ret = await team.lsUsers.stream('@foo:cli').collect()
+ t.same(ret, ['iarna', 'zkat'], 'got team members')
})
test('edit', t => {