11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst { resolve } = require('path') 31cb0ef41Sopenharmony_ciconst realRunScript = require('@npmcli/run-script') 41cb0ef41Sopenharmony_ciconst mockNpm = require('../../fixtures/mock-npm') 51cb0ef41Sopenharmony_ciconst { cleanCwd } = require('../../fixtures/clean-snapshot') 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst mockRs = async (t, { windows = false, runScript, ...opts } = {}) => { 81cb0ef41Sopenharmony_ci let RUN_SCRIPTS = [] 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci t.afterEach(() => RUN_SCRIPTS = []) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci const mock = await mockNpm(t, { 131cb0ef41Sopenharmony_ci ...opts, 141cb0ef41Sopenharmony_ci command: 'run-script', 151cb0ef41Sopenharmony_ci mocks: { 161cb0ef41Sopenharmony_ci '@npmcli/run-script': Object.assign( 171cb0ef41Sopenharmony_ci async rs => { 181cb0ef41Sopenharmony_ci if (runScript) { 191cb0ef41Sopenharmony_ci await runScript(rs) 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci RUN_SCRIPTS.push(rs) 221cb0ef41Sopenharmony_ci }, 231cb0ef41Sopenharmony_ci realRunScript 241cb0ef41Sopenharmony_ci ), 251cb0ef41Sopenharmony_ci '{LIB}/utils/is-windows.js': { isWindowsShell: windows }, 261cb0ef41Sopenharmony_ci }, 271cb0ef41Sopenharmony_ci }) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci return { 301cb0ef41Sopenharmony_ci ...mock, 311cb0ef41Sopenharmony_ci RUN_SCRIPTS: () => RUN_SCRIPTS, 321cb0ef41Sopenharmony_ci runScript: mock['run-script'], 331cb0ef41Sopenharmony_ci cleanLogs: () => mock.logs.error.flat().map(v => v.toString()).map(cleanCwd), 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_cit.test('completion', async t => { 381cb0ef41Sopenharmony_ci const completion = async (t, remain, pkg, isFish = false) => { 391cb0ef41Sopenharmony_ci const { runScript } = await mockRs(t, 401cb0ef41Sopenharmony_ci pkg ? { prefixDir: { 'package.json': JSON.stringify(pkg) } } : {} 411cb0ef41Sopenharmony_ci ) 421cb0ef41Sopenharmony_ci return runScript.completion({ conf: { argv: { remain } }, isFish }) 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci t.test('already have a script name', async t => { 461cb0ef41Sopenharmony_ci const res = await completion(t, ['npm', 'run', 'x']) 471cb0ef41Sopenharmony_ci t.equal(res, undefined) 481cb0ef41Sopenharmony_ci }) 491cb0ef41Sopenharmony_ci t.test('no package.json', async t => { 501cb0ef41Sopenharmony_ci const res = await completion(t, ['npm', 'run']) 511cb0ef41Sopenharmony_ci t.strictSame(res, []) 521cb0ef41Sopenharmony_ci }) 531cb0ef41Sopenharmony_ci t.test('has package.json, no scripts', async t => { 541cb0ef41Sopenharmony_ci const res = await completion(t, ['npm', 'run'], {}) 551cb0ef41Sopenharmony_ci t.strictSame(res, []) 561cb0ef41Sopenharmony_ci }) 571cb0ef41Sopenharmony_ci t.test('has package.json, with scripts', async t => { 581cb0ef41Sopenharmony_ci const res = await completion(t, ['npm', 'run'], { 591cb0ef41Sopenharmony_ci scripts: { hello: 'echo hello', world: 'echo world' }, 601cb0ef41Sopenharmony_ci }) 611cb0ef41Sopenharmony_ci t.strictSame(res, ['hello', 'world']) 621cb0ef41Sopenharmony_ci }) 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci t.test('fish shell', async t => { 651cb0ef41Sopenharmony_ci const res = await completion(t, ['npm', 'run'], { 661cb0ef41Sopenharmony_ci scripts: { hello: 'echo hello', world: 'echo world' }, 671cb0ef41Sopenharmony_ci }, true) 681cb0ef41Sopenharmony_ci t.strictSame(res, ['hello\techo hello', 'world\techo world']) 691cb0ef41Sopenharmony_ci }) 701cb0ef41Sopenharmony_ci}) 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_cit.test('fail if no package.json', async t => { 731cb0ef41Sopenharmony_ci const { runScript } = await mockRs(t) 741cb0ef41Sopenharmony_ci await t.rejects(runScript.exec([]), { code: 'ENOENT' }) 751cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['test']), { code: 'ENOENT' }) 761cb0ef41Sopenharmony_ci}) 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_cit.test('default env, start, and restart scripts', async t => { 791cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 801cb0ef41Sopenharmony_ci prefixDir: { 811cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }), 821cb0ef41Sopenharmony_ci 'server.js': 'console.log("hello, world")', 831cb0ef41Sopenharmony_ci }, 841cb0ef41Sopenharmony_ci }) 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci t.test('start', async t => { 871cb0ef41Sopenharmony_ci await runScript.exec(['start']) 881cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 891cb0ef41Sopenharmony_ci { 901cb0ef41Sopenharmony_ci path: npm.localPrefix, 911cb0ef41Sopenharmony_ci args: [], 921cb0ef41Sopenharmony_ci scriptShell: undefined, 931cb0ef41Sopenharmony_ci stdio: 'inherit', 941cb0ef41Sopenharmony_ci pkg: { name: 'x', version: '1.2.3', _id: 'x@1.2.3', scripts: {} }, 951cb0ef41Sopenharmony_ci event: 'start', 961cb0ef41Sopenharmony_ci }, 971cb0ef41Sopenharmony_ci ]) 981cb0ef41Sopenharmony_ci }) 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci t.test('env', async t => { 1011cb0ef41Sopenharmony_ci await runScript.exec(['env']) 1021cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 1031cb0ef41Sopenharmony_ci { 1041cb0ef41Sopenharmony_ci path: npm.localPrefix, 1051cb0ef41Sopenharmony_ci args: [], 1061cb0ef41Sopenharmony_ci scriptShell: undefined, 1071cb0ef41Sopenharmony_ci stdio: 'inherit', 1081cb0ef41Sopenharmony_ci pkg: { 1091cb0ef41Sopenharmony_ci name: 'x', 1101cb0ef41Sopenharmony_ci version: '1.2.3', 1111cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 1121cb0ef41Sopenharmony_ci scripts: { 1131cb0ef41Sopenharmony_ci env: 'env', 1141cb0ef41Sopenharmony_ci }, 1151cb0ef41Sopenharmony_ci }, 1161cb0ef41Sopenharmony_ci event: 'env', 1171cb0ef41Sopenharmony_ci }, 1181cb0ef41Sopenharmony_ci ]) 1191cb0ef41Sopenharmony_ci }) 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci t.test('restart', async t => { 1221cb0ef41Sopenharmony_ci await runScript.exec(['restart']) 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 1251cb0ef41Sopenharmony_ci { 1261cb0ef41Sopenharmony_ci path: npm.localPrefix, 1271cb0ef41Sopenharmony_ci args: [], 1281cb0ef41Sopenharmony_ci scriptShell: undefined, 1291cb0ef41Sopenharmony_ci stdio: 'inherit', 1301cb0ef41Sopenharmony_ci pkg: { 1311cb0ef41Sopenharmony_ci name: 'x', 1321cb0ef41Sopenharmony_ci version: '1.2.3', 1331cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 1341cb0ef41Sopenharmony_ci scripts: { 1351cb0ef41Sopenharmony_ci restart: 'npm stop --if-present && npm start', 1361cb0ef41Sopenharmony_ci }, 1371cb0ef41Sopenharmony_ci }, 1381cb0ef41Sopenharmony_ci event: 'restart', 1391cb0ef41Sopenharmony_ci }, 1401cb0ef41Sopenharmony_ci ]) 1411cb0ef41Sopenharmony_ci }) 1421cb0ef41Sopenharmony_ci}) 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_cit.test('default windows env', async t => { 1451cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 1461cb0ef41Sopenharmony_ci windows: true, 1471cb0ef41Sopenharmony_ci prefixDir: { 1481cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }), 1491cb0ef41Sopenharmony_ci 'server.js': 'console.log("hello, world")', 1501cb0ef41Sopenharmony_ci }, 1511cb0ef41Sopenharmony_ci }) 1521cb0ef41Sopenharmony_ci await runScript.exec(['env']) 1531cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 1541cb0ef41Sopenharmony_ci { 1551cb0ef41Sopenharmony_ci path: npm.localPrefix, 1561cb0ef41Sopenharmony_ci args: [], 1571cb0ef41Sopenharmony_ci scriptShell: undefined, 1581cb0ef41Sopenharmony_ci stdio: 'inherit', 1591cb0ef41Sopenharmony_ci pkg: { 1601cb0ef41Sopenharmony_ci name: 'x', 1611cb0ef41Sopenharmony_ci version: '1.2.3', 1621cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 1631cb0ef41Sopenharmony_ci scripts: { 1641cb0ef41Sopenharmony_ci env: 'SET', 1651cb0ef41Sopenharmony_ci }, 1661cb0ef41Sopenharmony_ci }, 1671cb0ef41Sopenharmony_ci event: 'env', 1681cb0ef41Sopenharmony_ci }, 1691cb0ef41Sopenharmony_ci ]) 1701cb0ef41Sopenharmony_ci}) 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_cit.test('non-default env script', async t => { 1731cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 1741cb0ef41Sopenharmony_ci prefixDir: { 1751cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 1761cb0ef41Sopenharmony_ci name: 'x', 1771cb0ef41Sopenharmony_ci version: '1.2.3', 1781cb0ef41Sopenharmony_ci scripts: { 1791cb0ef41Sopenharmony_ci env: 'hello', 1801cb0ef41Sopenharmony_ci }, 1811cb0ef41Sopenharmony_ci }), 1821cb0ef41Sopenharmony_ci }, 1831cb0ef41Sopenharmony_ci }) 1841cb0ef41Sopenharmony_ci 1851cb0ef41Sopenharmony_ci t.test('env', async t => { 1861cb0ef41Sopenharmony_ci await runScript.exec(['env']) 1871cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 1881cb0ef41Sopenharmony_ci { 1891cb0ef41Sopenharmony_ci path: npm.localPrefix, 1901cb0ef41Sopenharmony_ci args: [], 1911cb0ef41Sopenharmony_ci scriptShell: undefined, 1921cb0ef41Sopenharmony_ci stdio: 'inherit', 1931cb0ef41Sopenharmony_ci pkg: { 1941cb0ef41Sopenharmony_ci name: 'x', 1951cb0ef41Sopenharmony_ci version: '1.2.3', 1961cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 1971cb0ef41Sopenharmony_ci scripts: { 1981cb0ef41Sopenharmony_ci env: 'hello', 1991cb0ef41Sopenharmony_ci }, 2001cb0ef41Sopenharmony_ci }, 2011cb0ef41Sopenharmony_ci event: 'env', 2021cb0ef41Sopenharmony_ci }, 2031cb0ef41Sopenharmony_ci ]) 2041cb0ef41Sopenharmony_ci }) 2051cb0ef41Sopenharmony_ci}) 2061cb0ef41Sopenharmony_ci 2071cb0ef41Sopenharmony_cit.test('non-default env script windows', async t => { 2081cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 2091cb0ef41Sopenharmony_ci windows: true, 2101cb0ef41Sopenharmony_ci prefixDir: { 2111cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 2121cb0ef41Sopenharmony_ci name: 'x', 2131cb0ef41Sopenharmony_ci version: '1.2.3', 2141cb0ef41Sopenharmony_ci scripts: { 2151cb0ef41Sopenharmony_ci env: 'hello', 2161cb0ef41Sopenharmony_ci }, 2171cb0ef41Sopenharmony_ci }), 2181cb0ef41Sopenharmony_ci }, 2191cb0ef41Sopenharmony_ci }) 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ci await runScript.exec(['env']) 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 2241cb0ef41Sopenharmony_ci { 2251cb0ef41Sopenharmony_ci path: npm.localPrefix, 2261cb0ef41Sopenharmony_ci args: [], 2271cb0ef41Sopenharmony_ci scriptShell: undefined, 2281cb0ef41Sopenharmony_ci stdio: 'inherit', 2291cb0ef41Sopenharmony_ci pkg: { 2301cb0ef41Sopenharmony_ci name: 'x', 2311cb0ef41Sopenharmony_ci version: '1.2.3', 2321cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 2331cb0ef41Sopenharmony_ci scripts: { 2341cb0ef41Sopenharmony_ci env: 'hello', 2351cb0ef41Sopenharmony_ci }, 2361cb0ef41Sopenharmony_ci }, 2371cb0ef41Sopenharmony_ci event: 'env', 2381cb0ef41Sopenharmony_ci }, 2391cb0ef41Sopenharmony_ci ]) 2401cb0ef41Sopenharmony_ci}) 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_cit.test('try to run missing script', async t => { 2431cb0ef41Sopenharmony_ci t.test('errors', async t => { 2441cb0ef41Sopenharmony_ci const { runScript } = await mockRs(t, { 2451cb0ef41Sopenharmony_ci prefixDir: { 2461cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 2471cb0ef41Sopenharmony_ci scripts: { hello: 'world' }, 2481cb0ef41Sopenharmony_ci bin: { goodnight: 'moon' }, 2491cb0ef41Sopenharmony_ci }), 2501cb0ef41Sopenharmony_ci }, 2511cb0ef41Sopenharmony_ci }) 2521cb0ef41Sopenharmony_ci t.test('no suggestions', async t => { 2531cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['notevenclose']), 'Missing script: "notevenclose"') 2541cb0ef41Sopenharmony_ci }) 2551cb0ef41Sopenharmony_ci t.test('script suggestions', async t => { 2561cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['helo']), /Missing script: "helo"/) 2571cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['helo']), /npm run hello/) 2581cb0ef41Sopenharmony_ci }) 2591cb0ef41Sopenharmony_ci t.test('bin suggestions', async t => { 2601cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['goodneght']), /Missing script: "goodneght"/) 2611cb0ef41Sopenharmony_ci await t.rejects(runScript.exec(['goodneght']), /npm exec goodnight/) 2621cb0ef41Sopenharmony_ci }) 2631cb0ef41Sopenharmony_ci }) 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ci t.test('with --if-present', async t => { 2661cb0ef41Sopenharmony_ci const { runScript, RUN_SCRIPTS } = await mockRs(t, { 2671cb0ef41Sopenharmony_ci config: { 'if-present': true }, 2681cb0ef41Sopenharmony_ci prefixDir: { 2691cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 2701cb0ef41Sopenharmony_ci scripts: { hello: 'world' }, 2711cb0ef41Sopenharmony_ci bin: { goodnight: 'moon' }, 2721cb0ef41Sopenharmony_ci }), 2731cb0ef41Sopenharmony_ci }, 2741cb0ef41Sopenharmony_ci }) 2751cb0ef41Sopenharmony_ci await runScript.exec(['goodbye']) 2761cb0ef41Sopenharmony_ci t.strictSame(RUN_SCRIPTS(), [], 'did not try to run anything') 2771cb0ef41Sopenharmony_ci }) 2781cb0ef41Sopenharmony_ci}) 2791cb0ef41Sopenharmony_ci 2801cb0ef41Sopenharmony_cit.test('run pre/post hooks', async t => { 2811cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 2821cb0ef41Sopenharmony_ci prefixDir: { 2831cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 2841cb0ef41Sopenharmony_ci name: 'x', 2851cb0ef41Sopenharmony_ci version: '1.2.3', 2861cb0ef41Sopenharmony_ci scripts: { 2871cb0ef41Sopenharmony_ci preenv: 'echo before the env', 2881cb0ef41Sopenharmony_ci postenv: 'echo after the env', 2891cb0ef41Sopenharmony_ci }, 2901cb0ef41Sopenharmony_ci }), 2911cb0ef41Sopenharmony_ci }, 2921cb0ef41Sopenharmony_ci }) 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ci await runScript.exec(['env']) 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 2971cb0ef41Sopenharmony_ci { event: 'preenv' }, 2981cb0ef41Sopenharmony_ci { 2991cb0ef41Sopenharmony_ci path: npm.localPrefix, 3001cb0ef41Sopenharmony_ci args: [], 3011cb0ef41Sopenharmony_ci scriptShell: undefined, 3021cb0ef41Sopenharmony_ci stdio: 'inherit', 3031cb0ef41Sopenharmony_ci pkg: { 3041cb0ef41Sopenharmony_ci name: 'x', 3051cb0ef41Sopenharmony_ci version: '1.2.3', 3061cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 3071cb0ef41Sopenharmony_ci scripts: { 3081cb0ef41Sopenharmony_ci env: 'env', 3091cb0ef41Sopenharmony_ci }, 3101cb0ef41Sopenharmony_ci }, 3111cb0ef41Sopenharmony_ci event: 'env', 3121cb0ef41Sopenharmony_ci }, 3131cb0ef41Sopenharmony_ci { event: 'postenv' }, 3141cb0ef41Sopenharmony_ci ]) 3151cb0ef41Sopenharmony_ci}) 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_cit.test('skip pre/post hooks when using ignoreScripts', async t => { 3181cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 3191cb0ef41Sopenharmony_ci prefixDir: { 3201cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 3211cb0ef41Sopenharmony_ci name: 'x', 3221cb0ef41Sopenharmony_ci version: '1.2.3', 3231cb0ef41Sopenharmony_ci scripts: { 3241cb0ef41Sopenharmony_ci preenv: 'echo before the env', 3251cb0ef41Sopenharmony_ci postenv: 'echo after the env', 3261cb0ef41Sopenharmony_ci }, 3271cb0ef41Sopenharmony_ci }), 3281cb0ef41Sopenharmony_ci }, 3291cb0ef41Sopenharmony_ci config: { 'ignore-scripts': true }, 3301cb0ef41Sopenharmony_ci }) 3311cb0ef41Sopenharmony_ci 3321cb0ef41Sopenharmony_ci await runScript.exec(['env']) 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_ci t.same(RUN_SCRIPTS(), [ 3351cb0ef41Sopenharmony_ci { 3361cb0ef41Sopenharmony_ci path: npm.localPrefix, 3371cb0ef41Sopenharmony_ci args: [], 3381cb0ef41Sopenharmony_ci scriptShell: undefined, 3391cb0ef41Sopenharmony_ci stdio: 'inherit', 3401cb0ef41Sopenharmony_ci pkg: { 3411cb0ef41Sopenharmony_ci name: 'x', 3421cb0ef41Sopenharmony_ci version: '1.2.3', 3431cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 3441cb0ef41Sopenharmony_ci scripts: { 3451cb0ef41Sopenharmony_ci preenv: 'echo before the env', 3461cb0ef41Sopenharmony_ci postenv: 'echo after the env', 3471cb0ef41Sopenharmony_ci env: 'env', 3481cb0ef41Sopenharmony_ci }, 3491cb0ef41Sopenharmony_ci }, 3501cb0ef41Sopenharmony_ci banner: true, 3511cb0ef41Sopenharmony_ci event: 'env', 3521cb0ef41Sopenharmony_ci }, 3531cb0ef41Sopenharmony_ci ]) 3541cb0ef41Sopenharmony_ci}) 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_cit.test('run silent', async t => { 3571cb0ef41Sopenharmony_ci const { npm, runScript, RUN_SCRIPTS } = await mockRs(t, { 3581cb0ef41Sopenharmony_ci prefixDir: { 3591cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 3601cb0ef41Sopenharmony_ci name: 'x', 3611cb0ef41Sopenharmony_ci version: '1.2.3', 3621cb0ef41Sopenharmony_ci scripts: { 3631cb0ef41Sopenharmony_ci preenv: 'echo before the env', 3641cb0ef41Sopenharmony_ci postenv: 'echo after the env', 3651cb0ef41Sopenharmony_ci }, 3661cb0ef41Sopenharmony_ci }), 3671cb0ef41Sopenharmony_ci }, 3681cb0ef41Sopenharmony_ci config: { silent: true }, 3691cb0ef41Sopenharmony_ci }) 3701cb0ef41Sopenharmony_ci 3711cb0ef41Sopenharmony_ci await runScript.exec(['env']) 3721cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 3731cb0ef41Sopenharmony_ci { 3741cb0ef41Sopenharmony_ci event: 'preenv', 3751cb0ef41Sopenharmony_ci stdio: 'inherit', 3761cb0ef41Sopenharmony_ci }, 3771cb0ef41Sopenharmony_ci { 3781cb0ef41Sopenharmony_ci path: npm.localPrefix, 3791cb0ef41Sopenharmony_ci args: [], 3801cb0ef41Sopenharmony_ci scriptShell: undefined, 3811cb0ef41Sopenharmony_ci stdio: 'inherit', 3821cb0ef41Sopenharmony_ci pkg: { 3831cb0ef41Sopenharmony_ci name: 'x', 3841cb0ef41Sopenharmony_ci version: '1.2.3', 3851cb0ef41Sopenharmony_ci _id: 'x@1.2.3', 3861cb0ef41Sopenharmony_ci scripts: { 3871cb0ef41Sopenharmony_ci env: 'env', 3881cb0ef41Sopenharmony_ci }, 3891cb0ef41Sopenharmony_ci }, 3901cb0ef41Sopenharmony_ci event: 'env', 3911cb0ef41Sopenharmony_ci banner: false, 3921cb0ef41Sopenharmony_ci }, 3931cb0ef41Sopenharmony_ci { 3941cb0ef41Sopenharmony_ci event: 'postenv', 3951cb0ef41Sopenharmony_ci stdio: 'inherit', 3961cb0ef41Sopenharmony_ci }, 3971cb0ef41Sopenharmony_ci ]) 3981cb0ef41Sopenharmony_ci}) 3991cb0ef41Sopenharmony_ci 4001cb0ef41Sopenharmony_cit.test('list scripts', async t => { 4011cb0ef41Sopenharmony_ci const scripts = { 4021cb0ef41Sopenharmony_ci test: 'exit 2', 4031cb0ef41Sopenharmony_ci start: 'node server.js', 4041cb0ef41Sopenharmony_ci stop: 'node kill-server.js', 4051cb0ef41Sopenharmony_ci preenv: 'echo before the env', 4061cb0ef41Sopenharmony_ci postenv: 'echo after the env', 4071cb0ef41Sopenharmony_ci } 4081cb0ef41Sopenharmony_ci 4091cb0ef41Sopenharmony_ci const mockList = async (t, config = {}) => { 4101cb0ef41Sopenharmony_ci const mock = await mockRs(t, { 4111cb0ef41Sopenharmony_ci prefixDir: { 4121cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 4131cb0ef41Sopenharmony_ci name: 'x', 4141cb0ef41Sopenharmony_ci version: '1.2.3', 4151cb0ef41Sopenharmony_ci scripts, 4161cb0ef41Sopenharmony_ci }), 4171cb0ef41Sopenharmony_ci }, 4181cb0ef41Sopenharmony_ci config, 4191cb0ef41Sopenharmony_ci }) 4201cb0ef41Sopenharmony_ci 4211cb0ef41Sopenharmony_ci await mock.runScript.exec([]) 4221cb0ef41Sopenharmony_ci 4231cb0ef41Sopenharmony_ci return mock.outputs 4241cb0ef41Sopenharmony_ci } 4251cb0ef41Sopenharmony_ci 4261cb0ef41Sopenharmony_ci t.test('no args', async t => { 4271cb0ef41Sopenharmony_ci const output = await mockList(t) 4281cb0ef41Sopenharmony_ci t.strictSame( 4291cb0ef41Sopenharmony_ci output, 4301cb0ef41Sopenharmony_ci [ 4311cb0ef41Sopenharmony_ci ['Lifecycle scripts included in x@1.2.3:'], 4321cb0ef41Sopenharmony_ci [' test\n exit 2'], 4331cb0ef41Sopenharmony_ci [' start\n node server.js'], 4341cb0ef41Sopenharmony_ci [' stop\n node kill-server.js'], 4351cb0ef41Sopenharmony_ci ['\navailable via `npm run-script`:'], 4361cb0ef41Sopenharmony_ci [' preenv\n echo before the env'], 4371cb0ef41Sopenharmony_ci [' postenv\n echo after the env'], 4381cb0ef41Sopenharmony_ci [''], 4391cb0ef41Sopenharmony_ci ], 4401cb0ef41Sopenharmony_ci 'basic report' 4411cb0ef41Sopenharmony_ci ) 4421cb0ef41Sopenharmony_ci }) 4431cb0ef41Sopenharmony_ci 4441cb0ef41Sopenharmony_ci t.test('silent', async t => { 4451cb0ef41Sopenharmony_ci const outputs = await mockList(t, { silent: true }) 4461cb0ef41Sopenharmony_ci t.strictSame(outputs, []) 4471cb0ef41Sopenharmony_ci }) 4481cb0ef41Sopenharmony_ci t.test('warn json', async t => { 4491cb0ef41Sopenharmony_ci const outputs = await mockList(t, { json: true }) 4501cb0ef41Sopenharmony_ci t.strictSame(outputs, [[JSON.stringify(scripts, 0, 2)]], 'json report') 4511cb0ef41Sopenharmony_ci }) 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_ci t.test('parseable', async t => { 4541cb0ef41Sopenharmony_ci const outputs = await mockList(t, { parseable: true }) 4551cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 4561cb0ef41Sopenharmony_ci ['test:exit 2'], 4571cb0ef41Sopenharmony_ci ['start:node server.js'], 4581cb0ef41Sopenharmony_ci ['stop:node kill-server.js'], 4591cb0ef41Sopenharmony_ci ['preenv:echo before the env'], 4601cb0ef41Sopenharmony_ci ['postenv:echo after the env'], 4611cb0ef41Sopenharmony_ci ]) 4621cb0ef41Sopenharmony_ci }) 4631cb0ef41Sopenharmony_ci}) 4641cb0ef41Sopenharmony_ci 4651cb0ef41Sopenharmony_cit.test('list scripts when no scripts', async t => { 4661cb0ef41Sopenharmony_ci const { runScript, outputs } = await mockRs(t, { 4671cb0ef41Sopenharmony_ci prefixDir: { 4681cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 4691cb0ef41Sopenharmony_ci name: 'x', 4701cb0ef41Sopenharmony_ci version: '1.2.3', 4711cb0ef41Sopenharmony_ci }), 4721cb0ef41Sopenharmony_ci }, 4731cb0ef41Sopenharmony_ci }) 4741cb0ef41Sopenharmony_ci 4751cb0ef41Sopenharmony_ci await runScript.exec([]) 4761cb0ef41Sopenharmony_ci t.strictSame(outputs, [], 'nothing to report') 4771cb0ef41Sopenharmony_ci}) 4781cb0ef41Sopenharmony_ci 4791cb0ef41Sopenharmony_cit.test('list scripts, only commands', async t => { 4801cb0ef41Sopenharmony_ci const { runScript, outputs } = await mockRs(t, { 4811cb0ef41Sopenharmony_ci prefixDir: { 4821cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 4831cb0ef41Sopenharmony_ci name: 'x', 4841cb0ef41Sopenharmony_ci version: '1.2.3', 4851cb0ef41Sopenharmony_ci scripts: { preversion: 'echo doing the version dance' }, 4861cb0ef41Sopenharmony_ci }), 4871cb0ef41Sopenharmony_ci }, 4881cb0ef41Sopenharmony_ci }) 4891cb0ef41Sopenharmony_ci 4901cb0ef41Sopenharmony_ci await runScript.exec([]) 4911cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 4921cb0ef41Sopenharmony_ci ['Lifecycle scripts included in x@1.2.3:'], 4931cb0ef41Sopenharmony_ci [' preversion\n echo doing the version dance'], 4941cb0ef41Sopenharmony_ci [''], 4951cb0ef41Sopenharmony_ci ]) 4961cb0ef41Sopenharmony_ci}) 4971cb0ef41Sopenharmony_ci 4981cb0ef41Sopenharmony_cit.test('list scripts, only non-commands', async t => { 4991cb0ef41Sopenharmony_ci const { runScript, outputs } = await mockRs(t, { 5001cb0ef41Sopenharmony_ci prefixDir: { 5011cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5021cb0ef41Sopenharmony_ci name: 'x', 5031cb0ef41Sopenharmony_ci version: '1.2.3', 5041cb0ef41Sopenharmony_ci scripts: { glorp: 'echo doing the glerp glop' }, 5051cb0ef41Sopenharmony_ci }), 5061cb0ef41Sopenharmony_ci }, 5071cb0ef41Sopenharmony_ci }) 5081cb0ef41Sopenharmony_ci 5091cb0ef41Sopenharmony_ci await runScript.exec([]) 5101cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 5111cb0ef41Sopenharmony_ci ['Scripts available in x@1.2.3 via `npm run-script`:'], 5121cb0ef41Sopenharmony_ci [' glorp\n echo doing the glerp glop'], 5131cb0ef41Sopenharmony_ci [''], 5141cb0ef41Sopenharmony_ci ]) 5151cb0ef41Sopenharmony_ci}) 5161cb0ef41Sopenharmony_ci 5171cb0ef41Sopenharmony_cit.test('workspaces', async t => { 5181cb0ef41Sopenharmony_ci const mockWorkspaces = async (t, { 5191cb0ef41Sopenharmony_ci runScript, 5201cb0ef41Sopenharmony_ci prefixDir, 5211cb0ef41Sopenharmony_ci workspaces = true, 5221cb0ef41Sopenharmony_ci exec = [], 5231cb0ef41Sopenharmony_ci ...config 5241cb0ef41Sopenharmony_ci } = {}) => { 5251cb0ef41Sopenharmony_ci const mock = await mockRs(t, { 5261cb0ef41Sopenharmony_ci prefixDir: prefixDir || { 5271cb0ef41Sopenharmony_ci packages: { 5281cb0ef41Sopenharmony_ci a: { 5291cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5301cb0ef41Sopenharmony_ci name: 'a', 5311cb0ef41Sopenharmony_ci version: '1.0.0', 5321cb0ef41Sopenharmony_ci scripts: { glorp: 'echo a doing the glerp glop' }, 5331cb0ef41Sopenharmony_ci }), 5341cb0ef41Sopenharmony_ci }, 5351cb0ef41Sopenharmony_ci b: { 5361cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5371cb0ef41Sopenharmony_ci name: 'b', 5381cb0ef41Sopenharmony_ci version: '2.0.0', 5391cb0ef41Sopenharmony_ci scripts: { glorp: 'echo b doing the glerp glop' }, 5401cb0ef41Sopenharmony_ci }), 5411cb0ef41Sopenharmony_ci }, 5421cb0ef41Sopenharmony_ci c: { 5431cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5441cb0ef41Sopenharmony_ci name: 'c', 5451cb0ef41Sopenharmony_ci version: '1.0.0', 5461cb0ef41Sopenharmony_ci scripts: { 5471cb0ef41Sopenharmony_ci test: 'exit 0', 5481cb0ef41Sopenharmony_ci posttest: 'echo posttest', 5491cb0ef41Sopenharmony_ci lorem: 'echo c lorem', 5501cb0ef41Sopenharmony_ci }, 5511cb0ef41Sopenharmony_ci }), 5521cb0ef41Sopenharmony_ci }, 5531cb0ef41Sopenharmony_ci d: { 5541cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5551cb0ef41Sopenharmony_ci name: 'd', 5561cb0ef41Sopenharmony_ci version: '1.0.0', 5571cb0ef41Sopenharmony_ci scripts: { 5581cb0ef41Sopenharmony_ci test: 'exit 0', 5591cb0ef41Sopenharmony_ci posttest: 'echo posttest', 5601cb0ef41Sopenharmony_ci }, 5611cb0ef41Sopenharmony_ci }), 5621cb0ef41Sopenharmony_ci }, 5631cb0ef41Sopenharmony_ci e: { 5641cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5651cb0ef41Sopenharmony_ci name: 'e', 5661cb0ef41Sopenharmony_ci scripts: { test: 'exit 0', start: 'echo start something' }, 5671cb0ef41Sopenharmony_ci }), 5681cb0ef41Sopenharmony_ci }, 5691cb0ef41Sopenharmony_ci noscripts: { 5701cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5711cb0ef41Sopenharmony_ci name: 'noscripts', 5721cb0ef41Sopenharmony_ci version: '1.0.0', 5731cb0ef41Sopenharmony_ci }), 5741cb0ef41Sopenharmony_ci }, 5751cb0ef41Sopenharmony_ci }, 5761cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 5771cb0ef41Sopenharmony_ci name: 'x', 5781cb0ef41Sopenharmony_ci version: '1.2.3', 5791cb0ef41Sopenharmony_ci workspaces: ['packages/*'], 5801cb0ef41Sopenharmony_ci }), 5811cb0ef41Sopenharmony_ci }, 5821cb0ef41Sopenharmony_ci config: { 5831cb0ef41Sopenharmony_ci ...Array.isArray(workspaces) ? { workspace: workspaces } : { workspaces }, 5841cb0ef41Sopenharmony_ci ...config, 5851cb0ef41Sopenharmony_ci }, 5861cb0ef41Sopenharmony_ci runScript, 5871cb0ef41Sopenharmony_ci }) 5881cb0ef41Sopenharmony_ci if (exec) { 5891cb0ef41Sopenharmony_ci await mock.runScript.exec(exec) 5901cb0ef41Sopenharmony_ci } 5911cb0ef41Sopenharmony_ci return mock 5921cb0ef41Sopenharmony_ci } 5931cb0ef41Sopenharmony_ci 5941cb0ef41Sopenharmony_ci t.test('list all scripts', async t => { 5951cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t) 5961cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 5971cb0ef41Sopenharmony_ci ['Scripts available in a@1.0.0 via `npm run-script`:'], 5981cb0ef41Sopenharmony_ci [' glorp\n echo a doing the glerp glop'], 5991cb0ef41Sopenharmony_ci [''], 6001cb0ef41Sopenharmony_ci ['Scripts available in b@2.0.0 via `npm run-script`:'], 6011cb0ef41Sopenharmony_ci [' glorp\n echo b doing the glerp glop'], 6021cb0ef41Sopenharmony_ci [''], 6031cb0ef41Sopenharmony_ci ['Lifecycle scripts included in c@1.0.0:'], 6041cb0ef41Sopenharmony_ci [' test\n exit 0'], 6051cb0ef41Sopenharmony_ci [' posttest\n echo posttest'], 6061cb0ef41Sopenharmony_ci ['\navailable via `npm run-script`:'], 6071cb0ef41Sopenharmony_ci [' lorem\n echo c lorem'], 6081cb0ef41Sopenharmony_ci [''], 6091cb0ef41Sopenharmony_ci ['Lifecycle scripts included in d@1.0.0:'], 6101cb0ef41Sopenharmony_ci [' test\n exit 0'], 6111cb0ef41Sopenharmony_ci [' posttest\n echo posttest'], 6121cb0ef41Sopenharmony_ci [''], 6131cb0ef41Sopenharmony_ci ['Lifecycle scripts included in e:'], 6141cb0ef41Sopenharmony_ci [' test\n exit 0'], 6151cb0ef41Sopenharmony_ci [' start\n echo start something'], 6161cb0ef41Sopenharmony_ci [''], 6171cb0ef41Sopenharmony_ci ]) 6181cb0ef41Sopenharmony_ci }) 6191cb0ef41Sopenharmony_ci 6201cb0ef41Sopenharmony_ci t.test('list regular scripts, filtered by name', async t => { 6211cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { workspaces: ['a', 'b'] }) 6221cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 6231cb0ef41Sopenharmony_ci ['Scripts available in a@1.0.0 via `npm run-script`:'], 6241cb0ef41Sopenharmony_ci [' glorp\n echo a doing the glerp glop'], 6251cb0ef41Sopenharmony_ci [''], 6261cb0ef41Sopenharmony_ci ['Scripts available in b@2.0.0 via `npm run-script`:'], 6271cb0ef41Sopenharmony_ci [' glorp\n echo b doing the glerp glop'], 6281cb0ef41Sopenharmony_ci [''], 6291cb0ef41Sopenharmony_ci ]) 6301cb0ef41Sopenharmony_ci }) 6311cb0ef41Sopenharmony_ci 6321cb0ef41Sopenharmony_ci t.test('list regular scripts, filtered by path', async t => { 6331cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { workspaces: ['./packages/a'] }) 6341cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 6351cb0ef41Sopenharmony_ci ['Scripts available in a@1.0.0 via `npm run-script`:'], 6361cb0ef41Sopenharmony_ci [' glorp\n echo a doing the glerp glop'], 6371cb0ef41Sopenharmony_ci [''], 6381cb0ef41Sopenharmony_ci ]) 6391cb0ef41Sopenharmony_ci }) 6401cb0ef41Sopenharmony_ci 6411cb0ef41Sopenharmony_ci t.test('list regular scripts, filtered by parent folder', async t => { 6421cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { workspaces: ['./packages'] }) 6431cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 6441cb0ef41Sopenharmony_ci ['Scripts available in a@1.0.0 via `npm run-script`:'], 6451cb0ef41Sopenharmony_ci [' glorp\n echo a doing the glerp glop'], 6461cb0ef41Sopenharmony_ci [''], 6471cb0ef41Sopenharmony_ci ['Scripts available in b@2.0.0 via `npm run-script`:'], 6481cb0ef41Sopenharmony_ci [' glorp\n echo b doing the glerp glop'], 6491cb0ef41Sopenharmony_ci [''], 6501cb0ef41Sopenharmony_ci ['Lifecycle scripts included in c@1.0.0:'], 6511cb0ef41Sopenharmony_ci [' test\n exit 0'], 6521cb0ef41Sopenharmony_ci [' posttest\n echo posttest'], 6531cb0ef41Sopenharmony_ci ['\navailable via `npm run-script`:'], 6541cb0ef41Sopenharmony_ci [' lorem\n echo c lorem'], 6551cb0ef41Sopenharmony_ci [''], 6561cb0ef41Sopenharmony_ci ['Lifecycle scripts included in d@1.0.0:'], 6571cb0ef41Sopenharmony_ci [' test\n exit 0'], 6581cb0ef41Sopenharmony_ci [' posttest\n echo posttest'], 6591cb0ef41Sopenharmony_ci [''], 6601cb0ef41Sopenharmony_ci ['Lifecycle scripts included in e:'], 6611cb0ef41Sopenharmony_ci [' test\n exit 0'], 6621cb0ef41Sopenharmony_ci [' start\n echo start something'], 6631cb0ef41Sopenharmony_ci [''], 6641cb0ef41Sopenharmony_ci ]) 6651cb0ef41Sopenharmony_ci }) 6661cb0ef41Sopenharmony_ci 6671cb0ef41Sopenharmony_ci t.test('list all scripts with colors', async t => { 6681cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { color: 'always' }) 6691cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 6701cb0ef41Sopenharmony_ci [ 6711cb0ef41Sopenharmony_ci /* eslint-disable-next-line max-len */ 6721cb0ef41Sopenharmony_ci '\u001b[1mScripts\u001b[22m available in \x1B[32ma@1.0.0\x1B[39m via `\x1B[34mnpm run-script\x1B[39m`:', 6731cb0ef41Sopenharmony_ci ], 6741cb0ef41Sopenharmony_ci [' glorp\n \x1B[2mecho a doing the glerp glop\x1B[22m'], 6751cb0ef41Sopenharmony_ci [''], 6761cb0ef41Sopenharmony_ci [ 6771cb0ef41Sopenharmony_ci /* eslint-disable-next-line max-len */ 6781cb0ef41Sopenharmony_ci '\u001b[1mScripts\u001b[22m available in \x1B[32mb@2.0.0\x1B[39m via `\x1B[34mnpm run-script\x1B[39m`:', 6791cb0ef41Sopenharmony_ci ], 6801cb0ef41Sopenharmony_ci [' glorp\n \x1B[2mecho b doing the glerp glop\x1B[22m'], 6811cb0ef41Sopenharmony_ci [''], 6821cb0ef41Sopenharmony_ci ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32mc@1.0.0\x1B[39m:'], 6831cb0ef41Sopenharmony_ci [' test\n \x1B[2mexit 0\x1B[22m'], 6841cb0ef41Sopenharmony_ci [' posttest\n \x1B[2mecho posttest\x1B[22m'], 6851cb0ef41Sopenharmony_ci ['\navailable via `\x1B[34mnpm run-script\x1B[39m`:'], 6861cb0ef41Sopenharmony_ci [' lorem\n \x1B[2mecho c lorem\x1B[22m'], 6871cb0ef41Sopenharmony_ci [''], 6881cb0ef41Sopenharmony_ci ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32md@1.0.0\x1B[39m:'], 6891cb0ef41Sopenharmony_ci [' test\n \x1B[2mexit 0\x1B[22m'], 6901cb0ef41Sopenharmony_ci [' posttest\n \x1B[2mecho posttest\x1B[22m'], 6911cb0ef41Sopenharmony_ci [''], 6921cb0ef41Sopenharmony_ci ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32me\x1B[39m:'], 6931cb0ef41Sopenharmony_ci [' test\n \x1B[2mexit 0\x1B[22m'], 6941cb0ef41Sopenharmony_ci [' start\n \x1B[2mecho start something\x1B[22m'], 6951cb0ef41Sopenharmony_ci [''], 6961cb0ef41Sopenharmony_ci ]) 6971cb0ef41Sopenharmony_ci }) 6981cb0ef41Sopenharmony_ci 6991cb0ef41Sopenharmony_ci t.test('list all scripts --json', async t => { 7001cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { json: true }) 7011cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 7021cb0ef41Sopenharmony_ci [ 7031cb0ef41Sopenharmony_ci '{\n' + 7041cb0ef41Sopenharmony_ci ' "a": {\n' + 7051cb0ef41Sopenharmony_ci ' "glorp": "echo a doing the glerp glop"\n' + 7061cb0ef41Sopenharmony_ci ' },\n' + 7071cb0ef41Sopenharmony_ci ' "b": {\n' + 7081cb0ef41Sopenharmony_ci ' "glorp": "echo b doing the glerp glop"\n' + 7091cb0ef41Sopenharmony_ci ' },\n' + 7101cb0ef41Sopenharmony_ci ' "c": {\n' + 7111cb0ef41Sopenharmony_ci ' "test": "exit 0",\n' + 7121cb0ef41Sopenharmony_ci ' "posttest": "echo posttest",\n' + 7131cb0ef41Sopenharmony_ci ' "lorem": "echo c lorem"\n' + 7141cb0ef41Sopenharmony_ci ' },\n' + 7151cb0ef41Sopenharmony_ci ' "d": {\n' + 7161cb0ef41Sopenharmony_ci ' "test": "exit 0",\n' + 7171cb0ef41Sopenharmony_ci ' "posttest": "echo posttest"\n' + 7181cb0ef41Sopenharmony_ci ' },\n' + 7191cb0ef41Sopenharmony_ci ' "e": {\n' + 7201cb0ef41Sopenharmony_ci ' "test": "exit 0",\n' + 7211cb0ef41Sopenharmony_ci ' "start": "echo start something"\n' + 7221cb0ef41Sopenharmony_ci ' },\n' + 7231cb0ef41Sopenharmony_ci ' "noscripts": {}\n' + 7241cb0ef41Sopenharmony_ci '}', 7251cb0ef41Sopenharmony_ci ], 7261cb0ef41Sopenharmony_ci ]) 7271cb0ef41Sopenharmony_ci }) 7281cb0ef41Sopenharmony_ci 7291cb0ef41Sopenharmony_ci t.test('list all scripts --parseable', async t => { 7301cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { parseable: true }) 7311cb0ef41Sopenharmony_ci t.strictSame(outputs, [ 7321cb0ef41Sopenharmony_ci ['a:glorp:echo a doing the glerp glop'], 7331cb0ef41Sopenharmony_ci ['b:glorp:echo b doing the glerp glop'], 7341cb0ef41Sopenharmony_ci ['c:test:exit 0'], 7351cb0ef41Sopenharmony_ci ['c:posttest:echo posttest'], 7361cb0ef41Sopenharmony_ci ['c:lorem:echo c lorem'], 7371cb0ef41Sopenharmony_ci ['d:test:exit 0'], 7381cb0ef41Sopenharmony_ci ['d:posttest:echo posttest'], 7391cb0ef41Sopenharmony_ci ['e:test:exit 0'], 7401cb0ef41Sopenharmony_ci ['e:start:echo start something'], 7411cb0ef41Sopenharmony_ci ]) 7421cb0ef41Sopenharmony_ci }) 7431cb0ef41Sopenharmony_ci 7441cb0ef41Sopenharmony_ci t.test('list no scripts --loglevel=silent', async t => { 7451cb0ef41Sopenharmony_ci const { outputs } = await mockWorkspaces(t, { silent: true }) 7461cb0ef41Sopenharmony_ci t.strictSame(outputs, []) 7471cb0ef41Sopenharmony_ci }) 7481cb0ef41Sopenharmony_ci 7491cb0ef41Sopenharmony_ci t.test('run scripts across all workspaces', async t => { 7501cb0ef41Sopenharmony_ci const { npm, RUN_SCRIPTS } = await mockWorkspaces(t, { exec: ['test'] }) 7511cb0ef41Sopenharmony_ci 7521cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 7531cb0ef41Sopenharmony_ci { 7541cb0ef41Sopenharmony_ci path: resolve(npm.localPrefix, 'packages/c'), 7551cb0ef41Sopenharmony_ci pkg: { name: 'c', version: '1.0.0' }, 7561cb0ef41Sopenharmony_ci event: 'test', 7571cb0ef41Sopenharmony_ci }, 7581cb0ef41Sopenharmony_ci { 7591cb0ef41Sopenharmony_ci path: resolve(npm.localPrefix, 'packages/c'), 7601cb0ef41Sopenharmony_ci pkg: { name: 'c', version: '1.0.0' }, 7611cb0ef41Sopenharmony_ci event: 'posttest', 7621cb0ef41Sopenharmony_ci }, 7631cb0ef41Sopenharmony_ci { 7641cb0ef41Sopenharmony_ci path: resolve(npm.localPrefix, 'packages/d'), 7651cb0ef41Sopenharmony_ci pkg: { name: 'd', version: '1.0.0' }, 7661cb0ef41Sopenharmony_ci event: 'test', 7671cb0ef41Sopenharmony_ci }, 7681cb0ef41Sopenharmony_ci { 7691cb0ef41Sopenharmony_ci path: resolve(npm.localPrefix, 'packages/d'), 7701cb0ef41Sopenharmony_ci pkg: { name: 'd', version: '1.0.0' }, 7711cb0ef41Sopenharmony_ci event: 'posttest', 7721cb0ef41Sopenharmony_ci }, 7731cb0ef41Sopenharmony_ci { 7741cb0ef41Sopenharmony_ci path: resolve(npm.localPrefix, 'packages/e'), 7751cb0ef41Sopenharmony_ci pkg: { name: 'e' }, 7761cb0ef41Sopenharmony_ci event: 'test', 7771cb0ef41Sopenharmony_ci }, 7781cb0ef41Sopenharmony_ci ]) 7791cb0ef41Sopenharmony_ci }) 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_ci t.test('missing scripts in all workspaces', async t => { 7821cb0ef41Sopenharmony_ci const { runScript, RUN_SCRIPTS, cleanLogs } = await mockWorkspaces(t, { exec: null }) 7831cb0ef41Sopenharmony_ci 7841cb0ef41Sopenharmony_ci await runScript.exec(['missing-script']) 7851cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), []) 7861cb0ef41Sopenharmony_ci t.strictSame( 7871cb0ef41Sopenharmony_ci cleanLogs(), 7881cb0ef41Sopenharmony_ci [ 7891cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 7901cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 7911cb0ef41Sopenharmony_ci ' in workspace: a@1.0.0', 7921cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/a', 7931cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 7941cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 7951cb0ef41Sopenharmony_ci ' in workspace: b@2.0.0', 7961cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/b', 7971cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 7981cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 7991cb0ef41Sopenharmony_ci ' in workspace: c@1.0.0', 8001cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/c', 8011cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 8021cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 8031cb0ef41Sopenharmony_ci ' in workspace: d@1.0.0', 8041cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/d', 8051cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 8061cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 8071cb0ef41Sopenharmony_ci ' in workspace: e', 8081cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/e', 8091cb0ef41Sopenharmony_ci 'Lifecycle script `missing-script` failed with error:', 8101cb0ef41Sopenharmony_ci 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run', 8111cb0ef41Sopenharmony_ci ' in workspace: noscripts@1.0.0', 8121cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/noscripts', 8131cb0ef41Sopenharmony_ci ], 8141cb0ef41Sopenharmony_ci 'should log error msgs for each workspace script' 8151cb0ef41Sopenharmony_ci ) 8161cb0ef41Sopenharmony_ci }) 8171cb0ef41Sopenharmony_ci 8181cb0ef41Sopenharmony_ci t.test('missing scripts in some workspaces', async t => { 8191cb0ef41Sopenharmony_ci const { RUN_SCRIPTS, cleanLogs } = await mockWorkspaces(t, { 8201cb0ef41Sopenharmony_ci exec: ['test'], 8211cb0ef41Sopenharmony_ci workspaces: ['a', 'b', 'c', 'd'], 8221cb0ef41Sopenharmony_ci }) 8231cb0ef41Sopenharmony_ci 8241cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), []) 8251cb0ef41Sopenharmony_ci t.strictSame( 8261cb0ef41Sopenharmony_ci cleanLogs(), 8271cb0ef41Sopenharmony_ci [ 8281cb0ef41Sopenharmony_ci 'Lifecycle script `test` failed with error:', 8291cb0ef41Sopenharmony_ci 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run', 8301cb0ef41Sopenharmony_ci ' in workspace: a@1.0.0', 8311cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/a', 8321cb0ef41Sopenharmony_ci 'Lifecycle script `test` failed with error:', 8331cb0ef41Sopenharmony_ci 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run', 8341cb0ef41Sopenharmony_ci ' in workspace: b@2.0.0', 8351cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/b', 8361cb0ef41Sopenharmony_ci ], 8371cb0ef41Sopenharmony_ci 'should log error msgs for each workspace script' 8381cb0ef41Sopenharmony_ci ) 8391cb0ef41Sopenharmony_ci }) 8401cb0ef41Sopenharmony_ci 8411cb0ef41Sopenharmony_ci t.test('no workspaces when filtering by user args', async t => { 8421cb0ef41Sopenharmony_ci await t.rejects( 8431cb0ef41Sopenharmony_ci mockWorkspaces(t, { workspaces: ['foo', 'bar'] }), 8441cb0ef41Sopenharmony_ci 'No workspaces found:\n --workspace=foo --workspace=bar', 8451cb0ef41Sopenharmony_ci 'should throw error msg' 8461cb0ef41Sopenharmony_ci ) 8471cb0ef41Sopenharmony_ci }) 8481cb0ef41Sopenharmony_ci 8491cb0ef41Sopenharmony_ci t.test('no workspaces', async t => { 8501cb0ef41Sopenharmony_ci await t.rejects( 8511cb0ef41Sopenharmony_ci mockWorkspaces(t, { 8521cb0ef41Sopenharmony_ci prefixDir: { 8531cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 8541cb0ef41Sopenharmony_ci name: 'foo', 8551cb0ef41Sopenharmony_ci version: '1.0.0', 8561cb0ef41Sopenharmony_ci }), 8571cb0ef41Sopenharmony_ci }, 8581cb0ef41Sopenharmony_ci }), 8591cb0ef41Sopenharmony_ci /No workspaces found!/, 8601cb0ef41Sopenharmony_ci 'should throw error msg' 8611cb0ef41Sopenharmony_ci ) 8621cb0ef41Sopenharmony_ci }) 8631cb0ef41Sopenharmony_ci 8641cb0ef41Sopenharmony_ci t.test('single failed workspace run', async t => { 8651cb0ef41Sopenharmony_ci const { cleanLogs } = await mockWorkspaces(t, { 8661cb0ef41Sopenharmony_ci runScript: () => { 8671cb0ef41Sopenharmony_ci throw new Error('err') 8681cb0ef41Sopenharmony_ci }, 8691cb0ef41Sopenharmony_ci exec: ['test'], 8701cb0ef41Sopenharmony_ci workspaces: ['c'], 8711cb0ef41Sopenharmony_ci }) 8721cb0ef41Sopenharmony_ci 8731cb0ef41Sopenharmony_ci t.strictSame( 8741cb0ef41Sopenharmony_ci cleanLogs(), 8751cb0ef41Sopenharmony_ci [ 8761cb0ef41Sopenharmony_ci 'Lifecycle script `test` failed with error:', 8771cb0ef41Sopenharmony_ci 'Error: err', 8781cb0ef41Sopenharmony_ci ' in workspace: c@1.0.0', 8791cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/c', 8801cb0ef41Sopenharmony_ci ], 8811cb0ef41Sopenharmony_ci 'should log error msgs for each workspace script' 8821cb0ef41Sopenharmony_ci ) 8831cb0ef41Sopenharmony_ci }) 8841cb0ef41Sopenharmony_ci 8851cb0ef41Sopenharmony_ci t.test('failed workspace run with succeeded runs', async t => { 8861cb0ef41Sopenharmony_ci const { cleanLogs, RUN_SCRIPTS, prefix } = await mockWorkspaces(t, { 8871cb0ef41Sopenharmony_ci runScript: (opts) => { 8881cb0ef41Sopenharmony_ci if (opts.pkg.name === 'a') { 8891cb0ef41Sopenharmony_ci throw new Error('ERR') 8901cb0ef41Sopenharmony_ci } 8911cb0ef41Sopenharmony_ci }, 8921cb0ef41Sopenharmony_ci exec: ['glorp'], 8931cb0ef41Sopenharmony_ci workspaces: ['a', 'b'], 8941cb0ef41Sopenharmony_ci }) 8951cb0ef41Sopenharmony_ci 8961cb0ef41Sopenharmony_ci t.strictSame( 8971cb0ef41Sopenharmony_ci cleanLogs(), 8981cb0ef41Sopenharmony_ci [ 8991cb0ef41Sopenharmony_ci 'Lifecycle script `glorp` failed with error:', 9001cb0ef41Sopenharmony_ci 'Error: ERR', 9011cb0ef41Sopenharmony_ci ' in workspace: a@1.0.0', 9021cb0ef41Sopenharmony_ci ' at location: {CWD}/prefix/packages/a', 9031cb0ef41Sopenharmony_ci ], 9041cb0ef41Sopenharmony_ci 'should log error msgs for each workspace script' 9051cb0ef41Sopenharmony_ci ) 9061cb0ef41Sopenharmony_ci 9071cb0ef41Sopenharmony_ci t.match(RUN_SCRIPTS(), [ 9081cb0ef41Sopenharmony_ci { 9091cb0ef41Sopenharmony_ci path: resolve(prefix, 'packages/b'), 9101cb0ef41Sopenharmony_ci pkg: { name: 'b', version: '2.0.0' }, 9111cb0ef41Sopenharmony_ci event: 'glorp', 9121cb0ef41Sopenharmony_ci }, 9131cb0ef41Sopenharmony_ci ]) 9141cb0ef41Sopenharmony_ci }) 9151cb0ef41Sopenharmony_ci}) 916