diff options
author | Gar <gar+gh@danger.computer> | 2021-11-04 20:21:00 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-11-05 00:45:18 +0300 |
commit | 225645420cf3d13bc0b0d591f7f7bf21a9c24e47 (patch) | |
tree | 107797bef3206793cda93d7dad97f3ab54ef3cd8 /smoke-tests | |
parent | de45f90eebbf51205748ed3f09fbeab6cc000b3e (diff) |
chore: update to latest eslint and linting rules
This brings us in line with the rest of the linting rules we are wanting
to use on the npm cli repos.
There were several hundred over-length lines and instead of editing them
all by hand I piped the failing file through `prettier` and back through
`eslint` just to save some time and energy. This means there may be
some quirks in the linting those files have, but we can fix those if we
see them and they bother us.
Other than that there were about 50 lines that are legitimately
over-length, all are now explicitly overridden. Many are tests that
could be snapshots.
PR-URL: https://github.com/npm/cli/pull/3995
Credit: @wraithgar
Close: #3995
Reviewed-by: @lukekarrys
Diffstat (limited to 'smoke-tests')
-rw-r--r-- | smoke-tests/index.js | 150 | ||||
-rw-r--r-- | smoke-tests/server.js | 16 |
2 files changed, 77 insertions, 89 deletions
diff --git a/smoke-tests/index.js b/smoke-tests/index.js index bf99b4730..06ca3dee6 100644 --- a/smoke-tests/index.js +++ b/smoke-tests/index.js @@ -7,14 +7,20 @@ const rimraf = promisify(require('rimraf')) const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/') const cwd = normalizePath(process.cwd()) -t.cleanSnapshot = s => s.split(cwd).join('{CWD}') - .split(registry).join('https://registry.npmjs.org/') - .split(normalizePath(process.execPath)).join('node') - .split(process.cwd()).join('{CWD}') - .replace(/\\+/g, '/') - .replace(/\r\n/g, '\n') - .replace(/ \(in a browser\)/g, '') - .replace(/^npm@.* /mg, 'npm ') +t.cleanSnapshot = s => + s + .split(cwd) + .join('{CWD}') + .split(registry) + .join('https://registry.npmjs.org/') + .split(normalizePath(process.execPath)) + .join('node') + .split(process.cwd()) + .join('{CWD}') + .replace(/\\+/g, '/') + .replace(/\r\n/g, '\n') + .replace(/ \(in a browser\)/g, '') + .replace(/^npm@.* /gm, 'npm ') // setup server const { start, stop, registry } = require('./server.js') @@ -37,16 +43,23 @@ const env = { HOME: path, PATH: `${process.env.PATH}:${binLocation}`, } -const npmOpts = `--registry=${registry} --cache="${cacheLocation}" --userconfig="${userconfigLocation}" --no-audit --no-update-notifier --loglevel=silly` +const npmOpts = [ + `--registry=${registry}`, + `--cache="${cacheLocation}"`, + `--userconfig="${userconfigLocation}"`, + '--no-audit', + '--no-update-notifier', + '--loglevel=silly', +].join(' ') const npmBin = `"${process.execPath}" "${npmLocation}" ${npmOpts}` const exec = async cmd => { const res = await execAsync(cmd, { cwd: localPrefix, env }) - if (res.stderr) + if (res.stderr) { console.error(res.stderr) + } return String(res.stdout) } -const readFile = filename => - String(fs.readFileSync(resolve(localPrefix, filename))) +const readFile = filename => String(fs.readFileSync(resolve(localPrefix, filename))) // this test must come first, its package.json will be destroyed and the one // created in the next test (npm init) will create a new one that must be @@ -75,14 +88,22 @@ t.test('npm install sends correct user-agent', async t => { }) const cmd = `${npmBin} install fail_reflect_user_agent` - await t.rejects(exec(cmd), { - stderr: /workspaces\/false/, - }, 'workspaces/false is present in output') + await t.rejects( + exec(cmd), + { + stderr: /workspaces\/false/, + }, + 'workspaces/false is present in output' + ) const wsCmd = `${npmBin} install fail_reflect_user_agent --workspaces` - await t.rejects(exec(wsCmd), { - stderr: /workspaces\/true/, - }, 'workspaces/true is present in output') + await t.rejects( + exec(wsCmd), + { + stderr: /workspaces\/true/, + }, + 'workspaces/true is present in output' + ) }) t.test('npm init', async t => { @@ -97,39 +118,29 @@ t.test('npm init', async t => { t.test('npm (no args)', async t => { const cmd = `"${process.execPath}" "${npmLocation}" --no-audit --no-update-notifier` - const cmdRes = await execAsync(cmd, { cwd: localPrefix, env }) - .catch(err => { - t.equal(err.code, 1, 'should exit with error code') - return err - }) + const cmdRes = await execAsync(cmd, { cwd: localPrefix, env }).catch(err => { + t.equal(err.code, 1, 'should exit with error code') + return err + }) t.equal(cmdRes.stderr, '', 'should have no stderr output') - t.matchSnapshot(String(cmdRes.stdout), - 'should have expected no args output') + t.matchSnapshot(String(cmdRes.stdout), 'should have expected no args output') }) t.test('npm install prodDep@version', async t => { const cmd = `${npmBin} install abbrev@1.0.4` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected install reify output') - t.matchSnapshot( - readFile('package.json'), - 'should have expected package.json result' - ) - t.matchSnapshot( - readFile('package-lock.json'), - 'should have expected lockfile result' - ) + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected install reify output') + t.matchSnapshot(readFile('package.json'), 'should have expected package.json result') + t.matchSnapshot(readFile('package-lock.json'), 'should have expected lockfile result') }) t.test('npm install dev dep', async t => { const cmd = `${npmBin} install -D promise-all-reject-late` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected dev dep added reify output') + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected dev dep added reify output') t.matchSnapshot( readFile('package.json'), 'should have expected dev dep added package.json result' @@ -144,32 +155,28 @@ t.test('npm ls', async t => { const cmd = `${npmBin} ls` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected ls output') + t.matchSnapshot(cmdRes, 'should have expected ls output') }) t.test('npm fund', async t => { const cmd = `${npmBin} fund` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected fund output') + t.matchSnapshot(cmdRes, 'should have expected fund output') }) t.test('npm explain', async t => { const cmd = `${npmBin} explain abbrev` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected explain output') + t.matchSnapshot(cmdRes, 'should have expected explain output') }) t.test('npm diff', async t => { const cmd = `${npmBin} diff --diff=abbrev@1.0.4 --diff=abbrev@1.1.1` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected diff output') + t.matchSnapshot(cmdRes, 'should have expected diff output') }) t.test('npm outdated', async t => { @@ -180,16 +187,14 @@ t.test('npm outdated', async t => { }) t.not(cmdRes.stderr, '', 'should have stderr output') - t.matchSnapshot(String(cmdRes.stdout), - 'should have expected outdated output') + t.matchSnapshot(String(cmdRes.stdout), 'should have expected outdated output') }) t.test('npm set-script', async t => { const cmd = `${npmBin} set-script "hello" "echo Hello"` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected set-script output') + t.matchSnapshot(cmdRes, 'should have expected set-script output') t.matchSnapshot( readFile('package.json'), 'should have expected script added package.json result' @@ -200,68 +205,49 @@ t.test('npm run-script', async t => { const cmd = `${npmBin} run hello` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected run-script output') + t.matchSnapshot(cmdRes, 'should have expected run-script output') }) t.test('npm prefix', async t => { const cmd = `${npmBin} prefix` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected prefix output') + t.matchSnapshot(cmdRes, 'should have expected prefix output') }) t.test('npm view', async t => { const cmd = `${npmBin} view abbrev@1.0.4` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes, - 'should have expected view output') + t.matchSnapshot(cmdRes, 'should have expected view output') }) t.test('npm update dep', async t => { const cmd = `${npmBin} update abbrev` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected update reify output') - t.matchSnapshot( - readFile('package.json'), - 'should have expected update package.json result' - ) - t.matchSnapshot( - readFile('package-lock.json'), - 'should have expected update lockfile result' - ) + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected update reify output') + t.matchSnapshot(readFile('package.json'), 'should have expected update package.json result') + t.matchSnapshot(readFile('package-lock.json'), 'should have expected update lockfile result') }) t.test('npm uninstall', async t => { const cmd = `${npmBin} uninstall promise-all-reject-late` const cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected uninstall reify output') - t.matchSnapshot( - readFile('package.json'), - 'should have expected uninstall package.json result' - ) - t.matchSnapshot( - readFile('package-lock.json'), - 'should have expected uninstall lockfile result' - ) + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected uninstall reify output') + t.matchSnapshot(readFile('package.json'), 'should have expected uninstall package.json result') + t.matchSnapshot(readFile('package-lock.json'), 'should have expected uninstall lockfile result') }) t.test('npm pkg', async t => { let cmd = `${npmBin} pkg get license` let cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected pkg get output') + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected pkg get output') cmd = `${npmBin} pkg set tap[test-env][0]=LC_ALL=sk` cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected pkg set output') + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected pkg set output') t.matchSnapshot( readFile('package.json'), @@ -270,13 +256,11 @@ t.test('npm pkg', async t => { cmd = `${npmBin} pkg get` cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should print package.json contents') + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should print package.json contents') cmd = `${npmBin} pkg delete tap` cmdRes = await exec(cmd) - t.matchSnapshot(cmdRes.replace(/in.*s/, ''), - 'should have expected pkg delete output') + t.matchSnapshot(cmdRes.replace(/in.*s/, ''), 'should have expected pkg delete output') t.matchSnapshot( readFile('package.json'), diff --git a/smoke-tests/server.js b/smoke-tests/server.js index e0ac0c94e..31ffebb2a 100644 --- a/smoke-tests/server.js +++ b/smoke-tests/server.js @@ -1,6 +1,6 @@ /* istanbul ignore file */ -const {join, dirname, basename} = require('path') -const {existsSync, readFileSync, writeFileSync} = require('fs') +const { join, dirname, basename } = require('path') +const { existsSync, readFileSync, writeFileSync } = require('fs') const PORT = 12345 + (+process.env.TAP_CHILD_ID || 0) const http = require('http') const https = require('https') @@ -86,8 +86,9 @@ const startServer = () => new Promise((res, rej) => { https.request(opts) .on('response', upstream => handleUpstream(upstream)) .end(Buffer.concat(body)) - } else + } else { handleUpstream(upstream) + } }).end(Buffer.concat(body)) } else { res.setHeader('content-encoding', 'gzip') @@ -195,8 +196,9 @@ const startServer = () => new Promise((res, rej) => { const errorStatus = upstream.statusCode >= 300 || upstream.statusCode < 200 - if (errorStatus) + if (errorStatus) { console.error('UPSTREAM ERROR', upstream.statusCode) + } const ct = upstream.headers['content-type'] const isJson = ct.includes('application/json') @@ -217,8 +219,9 @@ const startServer = () => new Promise((res, rej) => { const minFile = file.replace(/\.json$/, '.min.json') writeFileSync(minFile, JSON.stringify(mrm(obj), 0, 2) + '\n') console.error('WROTE JSONS', [file, minFile]) - } else + } else { writeFileSync(file, out) + } } res.end(out) }) @@ -227,8 +230,9 @@ const startServer = () => new Promise((res, rej) => { } res.statusCode = er.code === 'ENOENT' ? 404 : 500 - if (res.method === 'GET') + if (res.method === 'GET') { console.error(er) + } res.setHeader('content-type', 'text/plain') res.end(er.stack) } |