Best JavaScript code snippet using wpt
run-script.js
Source:run-script.js
1const t = require('tap')2const { resolve } = require('path')3const { fake: mockNpm } = require('../../fixtures/mock-npm')4const normalizePath = p => p.replace(/\\+/g, '/').replace(/\r\n/g, '\n')5const cleanOutput = str => normalizePath(str).replace(normalizePath(process.cwd()), '{CWD}')6const RUN_SCRIPTS = []7const flatOptions = {8 scriptShell: undefined,9}10const defaultLoglevel = 'info'11const config = {12 json: false,13 parseable: false,14 'if-present': false,15 loglevel: defaultLoglevel,16}17const npm = mockNpm({18 localPrefix: __dirname,19 flatOptions,20 config,21 cmd: c => {22 return { description: `test ${c} description` }23 },24 output: (...msg) => output.push(msg),25})26const setLoglevel = (t, level) => {27 npm.config.set('loglevel', level)28 t.teardown(() => {29 npm.config.set('loglevel', defaultLoglevel)30 })31}32const output = []33const log = {34 error: () => null,35}36t.afterEach(() => {37 npm.color = false38 log.error = () => null39 output.length = 040 RUN_SCRIPTS.length = 041 config['if-present'] = false42 config.json = false43 config.parseable = false44})45const getRS = windows => {46 const RunScript = t.mock('../../../lib/commands/run-script.js', {47 '@npmcli/run-script': Object.assign(48 async opts => {49 RUN_SCRIPTS.push(opts)50 },51 {52 isServerPackage: require('@npmcli/run-script').isServerPackage,53 }54 ),55 'proc-log': log,56 '../../../lib/utils/is-windows-shell.js': windows,57 })58 return new RunScript(npm)59}60const runScript = getRS(false)61const runScriptWin = getRS(true)62const { writeFileSync } = require('fs')63t.test('completion', t => {64 const dir = t.testdir()65 npm.localPrefix = dir66 t.test('already have a script name', async t => {67 const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run', 'x'] } } })68 t.equal(res, undefined)69 t.end()70 })71 t.test('no package.json', async t => {72 const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run'] } } })73 t.strictSame(res, [])74 t.end()75 })76 t.test('has package.json, no scripts', async t => {77 writeFileSync(`${dir}/package.json`, JSON.stringify({}))78 const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run'] } } })79 t.strictSame(res, [])80 t.end()81 })82 t.test('has package.json, with scripts', async t => {83 writeFileSync(84 `${dir}/package.json`,85 JSON.stringify({86 scripts: { hello: 'echo hello', world: 'echo world' },87 })88 )89 const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run'] } } })90 t.strictSame(res, ['hello', 'world'])91 t.end()92 })93 t.end()94})95t.test('fail if no package.json', async t => {96 t.plan(2)97 npm.localPrefix = t.testdir()98 await t.rejects(runScript.exec([]), { code: 'ENOENT' })99 await t.rejects(runScript.exec(['test']), { code: 'ENOENT' })100})101t.test('default env, start, and restart scripts', t => {102 npm.localPrefix = t.testdir({103 'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }),104 'server.js': 'console.log("hello, world")',105 })106 t.test('start', async t => {107 await runScript.exec(['start'])108 t.match(RUN_SCRIPTS, [109 {110 path: npm.localPrefix,111 args: [],112 scriptShell: undefined,113 stdio: 'inherit',114 stdioString: true,115 pkg: { name: 'x', version: '1.2.3', _id: 'x@1.2.3', scripts: {} },116 event: 'start',117 },118 ])119 })120 t.test('env', async t => {121 await runScript.exec(['env'])122 t.match(RUN_SCRIPTS, [123 {124 path: npm.localPrefix,125 args: [],126 scriptShell: undefined,127 stdio: 'inherit',128 stdioString: true,129 pkg: {130 name: 'x',131 version: '1.2.3',132 _id: 'x@1.2.3',133 scripts: {134 env: 'env',135 },136 },137 event: 'env',138 },139 ])140 })141 t.test('windows env', async t => {142 await runScriptWin.exec(['env'])143 t.match(RUN_SCRIPTS, [144 {145 path: npm.localPrefix,146 args: [],147 scriptShell: undefined,148 stdio: 'inherit',149 stdioString: true,150 pkg: {151 name: 'x',152 version: '1.2.3',153 _id: 'x@1.2.3',154 scripts: {155 env: 'SET',156 },157 },158 event: 'env',159 },160 ])161 })162 t.test('restart', async t => {163 await runScript.exec(['restart'])164 t.match(RUN_SCRIPTS, [165 {166 path: npm.localPrefix,167 args: [],168 scriptShell: undefined,169 stdio: 'inherit',170 stdioString: true,171 pkg: {172 name: 'x',173 version: '1.2.3',174 _id: 'x@1.2.3',175 scripts: {176 restart: 'npm stop --if-present && npm start',177 },178 },179 event: 'restart',180 },181 ])182 })183 t.end()184})185t.test('non-default env script', t => {186 npm.localPrefix = t.testdir({187 'package.json': JSON.stringify({188 name: 'x',189 version: '1.2.3',190 scripts: {191 env: 'hello',192 },193 }),194 })195 t.test('env', async t => {196 await runScript.exec(['env'])197 t.match(RUN_SCRIPTS, [198 {199 path: npm.localPrefix,200 args: [],201 scriptShell: undefined,202 stdio: 'inherit',203 stdioString: true,204 pkg: {205 name: 'x',206 version: '1.2.3',207 _id: 'x@1.2.3',208 scripts: {209 env: 'hello',210 },211 },212 event: 'env',213 },214 ])215 })216 t.test('env windows', async t => {217 await runScriptWin.exec(['env'])218 t.match(RUN_SCRIPTS, [219 {220 path: npm.localPrefix,221 args: [],222 scriptShell: undefined,223 stdio: 'inherit',224 stdioString: true,225 pkg: {226 name: 'x',227 version: '1.2.3',228 _id: 'x@1.2.3',229 scripts: {230 env: 'hello',231 },232 },233 event: 'env',234 },235 ])236 })237 t.end()238})239t.test('try to run missing script', t => {240 npm.localPrefix = t.testdir({241 'package.json': JSON.stringify({242 scripts: { hello: 'world' },243 bin: { goodnight: 'moon' },244 }),245 })246 t.test('no suggestions', async t => {247 await t.rejects(runScript.exec(['notevenclose']), 'Missing script: "notevenclose"')248 })249 t.test('script suggestions', async t => {250 await t.rejects(runScript.exec(['helo']), /Missing script: "helo"/)251 await t.rejects(runScript.exec(['helo']), /npm run hello/)252 })253 t.test('bin suggestions', async t => {254 await t.rejects(runScript.exec(['goodneght']), /Missing script: "goodneght"/)255 await t.rejects(runScript.exec(['goodneght']), /npm exec goodnight/)256 })257 t.test('with --if-present', async t => {258 config['if-present'] = true259 await runScript.exec(['goodbye'])260 t.strictSame(RUN_SCRIPTS, [], 'did not try to run anything')261 })262 t.end()263})264t.test('run pre/post hooks', async t => {265 npm.localPrefix = t.testdir({266 'package.json': JSON.stringify({267 name: 'x',268 version: '1.2.3',269 scripts: {270 preenv: 'echo before the env',271 postenv: 'echo after the env',272 },273 }),274 })275 await runScript.exec(['env'])276 t.match(RUN_SCRIPTS, [277 { event: 'preenv' },278 {279 path: npm.localPrefix,280 args: [],281 scriptShell: undefined,282 stdio: 'inherit',283 stdioString: true,284 pkg: {285 name: 'x',286 version: '1.2.3',287 _id: 'x@1.2.3',288 scripts: {289 env: 'env',290 },291 },292 event: 'env',293 },294 { event: 'postenv' },295 ])296})297t.test('skip pre/post hooks when using ignoreScripts', async t => {298 config['ignore-scripts'] = true299 npm.localPrefix = t.testdir({300 'package.json': JSON.stringify({301 name: 'x',302 version: '1.2.3',303 scripts: {304 preenv: 'echo before the env',305 postenv: 'echo after the env',306 },307 }),308 })309 await runScript.exec(['env'])310 t.same(RUN_SCRIPTS, [311 {312 path: npm.localPrefix,313 args: [],314 scriptShell: undefined,315 stdio: 'inherit',316 stdioString: true,317 pkg: {318 name: 'x',319 version: '1.2.3',320 _id: 'x@1.2.3',321 scripts: {322 preenv: 'echo before the env',323 postenv: 'echo after the env',324 env: 'env',325 },326 },327 banner: true,328 event: 'env',329 },330 ])331 delete config['ignore-scripts']332})333t.test('run silent', async t => {334 setLoglevel(t, 'silent')335 npm.localPrefix = t.testdir({336 'package.json': JSON.stringify({337 name: 'x',338 version: '1.2.3',339 scripts: {340 preenv: 'echo before the env',341 postenv: 'echo after the env',342 },343 }),344 })345 await runScript.exec(['env'])346 t.match(RUN_SCRIPTS, [347 {348 event: 'preenv',349 stdio: 'inherit',350 },351 {352 path: npm.localPrefix,353 args: [],354 scriptShell: undefined,355 stdio: 'inherit',356 stdioString: true,357 pkg: {358 name: 'x',359 version: '1.2.3',360 _id: 'x@1.2.3',361 scripts: {362 env: 'env',363 },364 },365 event: 'env',366 banner: false,367 },368 {369 event: 'postenv',370 stdio: 'inherit',371 },372 ])373})374t.test('list scripts', t => {375 const scripts = {376 test: 'exit 2',377 start: 'node server.js',378 stop: 'node kill-server.js',379 preenv: 'echo before the env',380 postenv: 'echo after the env',381 }382 npm.localPrefix = t.testdir({383 'package.json': JSON.stringify({384 name: 'x',385 version: '1.2.3',386 scripts,387 }),388 })389 t.test('no args', async t => {390 await runScript.exec([])391 t.strictSame(392 output,393 [394 ['Lifecycle scripts included in x@1.2.3:'],395 [' test\n exit 2'],396 [' start\n node server.js'],397 [' stop\n node kill-server.js'],398 ['\navailable via `npm run-script`:'],399 [' preenv\n echo before the env'],400 [' postenv\n echo after the env'],401 [''],402 ],403 'basic report'404 )405 })406 t.test('silent', async t => {407 setLoglevel(t, 'silent')408 await runScript.exec([])409 t.strictSame(output, [])410 })411 t.test('warn json', async t => {412 config.json = true413 await runScript.exec([])414 t.strictSame(output, [[JSON.stringify(scripts, 0, 2)]], 'json report')415 })416 t.test('parseable', async t => {417 config.parseable = true418 await runScript.exec([])419 t.strictSame(output, [420 ['test:exit 2'],421 ['start:node server.js'],422 ['stop:node kill-server.js'],423 ['preenv:echo before the env'],424 ['postenv:echo after the env'],425 ])426 })427 t.end()428})429t.test('list scripts when no scripts', async t => {430 npm.localPrefix = t.testdir({431 'package.json': JSON.stringify({432 name: 'x',433 version: '1.2.3',434 }),435 })436 await runScript.exec([])437 t.strictSame(output, [], 'nothing to report')438})439t.test('list scripts, only commands', async t => {440 npm.localPrefix = t.testdir({441 'package.json': JSON.stringify({442 name: 'x',443 version: '1.2.3',444 scripts: { preversion: 'echo doing the version dance' },445 }),446 })447 await runScript.exec([])448 t.strictSame(output, [449 ['Lifecycle scripts included in x@1.2.3:'],450 [' preversion\n echo doing the version dance'],451 [''],452 ])453})454t.test('list scripts, only non-commands', async t => {455 npm.localPrefix = t.testdir({456 'package.json': JSON.stringify({457 name: 'x',458 version: '1.2.3',459 scripts: { glorp: 'echo doing the glerp glop' },460 }),461 })462 await runScript.exec([])463 t.strictSame(output, [464 ['Scripts available in x@1.2.3 via `npm run-script`:'],465 [' glorp\n echo doing the glerp glop'],466 [''],467 ])468})469t.test('workspaces', t => {470 npm.localPrefix = t.testdir({471 packages: {472 a: {473 'package.json': JSON.stringify({474 name: 'a',475 version: '1.0.0',476 scripts: { glorp: 'echo a doing the glerp glop' },477 }),478 },479 b: {480 'package.json': JSON.stringify({481 name: 'b',482 version: '2.0.0',483 scripts: { glorp: 'echo b doing the glerp glop' },484 }),485 },486 c: {487 'package.json': JSON.stringify({488 name: 'c',489 version: '1.0.0',490 scripts: {491 test: 'exit 0',492 posttest: 'echo posttest',493 lorem: 'echo c lorem',494 },495 }),496 },497 d: {498 'package.json': JSON.stringify({499 name: 'd',500 version: '1.0.0',501 scripts: {502 test: 'exit 0',503 posttest: 'echo posttest',504 },505 }),506 },507 e: {508 'package.json': JSON.stringify({509 name: 'e',510 scripts: { test: 'exit 0', start: 'echo start something' },511 }),512 },513 noscripts: {514 'package.json': JSON.stringify({515 name: 'noscripts',516 version: '1.0.0',517 }),518 },519 },520 'package.json': JSON.stringify({521 name: 'x',522 version: '1.2.3',523 workspaces: ['packages/*'],524 }),525 })526 t.test('list all scripts', async t => {527 await runScript.execWorkspaces([], [])528 t.strictSame(output, [529 ['Scripts available in a@1.0.0 via `npm run-script`:'],530 [' glorp\n echo a doing the glerp glop'],531 [''],532 ['Scripts available in b@2.0.0 via `npm run-script`:'],533 [' glorp\n echo b doing the glerp glop'],534 [''],535 ['Lifecycle scripts included in c@1.0.0:'],536 [' test\n exit 0'],537 [' posttest\n echo posttest'],538 ['\navailable via `npm run-script`:'],539 [' lorem\n echo c lorem'],540 [''],541 ['Lifecycle scripts included in d@1.0.0:'],542 [' test\n exit 0'],543 [' posttest\n echo posttest'],544 [''],545 ['Lifecycle scripts included in e:'],546 [' test\n exit 0'],547 [' start\n echo start something'],548 [''],549 ])550 })551 t.test('list regular scripts, filtered by name', async t => {552 await runScript.execWorkspaces([], ['a', 'b'])553 t.strictSame(output, [554 ['Scripts available in a@1.0.0 via `npm run-script`:'],555 [' glorp\n echo a doing the glerp glop'],556 [''],557 ['Scripts available in b@2.0.0 via `npm run-script`:'],558 [' glorp\n echo b doing the glerp glop'],559 [''],560 ])561 })562 t.test('list regular scripts, filtered by path', async t => {563 await runScript.execWorkspaces([], ['./packages/a'])564 t.strictSame(output, [565 ['Scripts available in a@1.0.0 via `npm run-script`:'],566 [' glorp\n echo a doing the glerp glop'],567 [''],568 ])569 })570 t.test('list regular scripts, filtered by parent folder', async t => {571 await runScript.execWorkspaces([], ['./packages'])572 t.strictSame(output, [573 ['Scripts available in a@1.0.0 via `npm run-script`:'],574 [' glorp\n echo a doing the glerp glop'],575 [''],576 ['Scripts available in b@2.0.0 via `npm run-script`:'],577 [' glorp\n echo b doing the glerp glop'],578 [''],579 ['Lifecycle scripts included in c@1.0.0:'],580 [' test\n exit 0'],581 [' posttest\n echo posttest'],582 ['\navailable via `npm run-script`:'],583 [' lorem\n echo c lorem'],584 [''],585 ['Lifecycle scripts included in d@1.0.0:'],586 [' test\n exit 0'],587 [' posttest\n echo posttest'],588 [''],589 ['Lifecycle scripts included in e:'],590 [' test\n exit 0'],591 [' start\n echo start something'],592 [''],593 ])594 })595 t.test('list all scripts with colors', async t => {596 npm.color = true597 await runScript.execWorkspaces([], [])598 t.strictSame(output, [599 [600 /* eslint-disable-next-line max-len */601 '\u001b[1mScripts\u001b[22m available in \x1B[32ma@1.0.0\x1B[39m via `\x1B[34mnpm run-script\x1B[39m`:',602 ],603 [' glorp\n \x1B[2mecho a doing the glerp glop\x1B[22m'],604 [''],605 [606 /* eslint-disable-next-line max-len */607 '\u001b[1mScripts\u001b[22m available in \x1B[32mb@2.0.0\x1B[39m via `\x1B[34mnpm run-script\x1B[39m`:',608 ],609 [' glorp\n \x1B[2mecho b doing the glerp glop\x1B[22m'],610 [''],611 ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32mc@1.0.0\x1B[39m:'],612 [' test\n \x1B[2mexit 0\x1B[22m'],613 [' posttest\n \x1B[2mecho posttest\x1B[22m'],614 ['\navailable via `\x1B[34mnpm run-script\x1B[39m`:'],615 [' lorem\n \x1B[2mecho c lorem\x1B[22m'],616 [''],617 ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32md@1.0.0\x1B[39m:'],618 [' test\n \x1B[2mexit 0\x1B[22m'],619 [' posttest\n \x1B[2mecho posttest\x1B[22m'],620 [''],621 ['\x1B[0m\x1B[1mLifecycle scripts\x1B[22m\x1B[0m included in \x1B[32me\x1B[39m:'],622 [' test\n \x1B[2mexit 0\x1B[22m'],623 [' start\n \x1B[2mecho start something\x1B[22m'],624 [''],625 ])626 })627 t.test('list all scripts --json', async t => {628 config.json = true629 await runScript.execWorkspaces([], [])630 t.strictSame(output, [631 [632 '{\n' +633 ' "a": {\n' +634 ' "glorp": "echo a doing the glerp glop"\n' +635 ' },\n' +636 ' "b": {\n' +637 ' "glorp": "echo b doing the glerp glop"\n' +638 ' },\n' +639 ' "c": {\n' +640 ' "test": "exit 0",\n' +641 ' "posttest": "echo posttest",\n' +642 ' "lorem": "echo c lorem"\n' +643 ' },\n' +644 ' "d": {\n' +645 ' "test": "exit 0",\n' +646 ' "posttest": "echo posttest"\n' +647 ' },\n' +648 ' "e": {\n' +649 ' "test": "exit 0",\n' +650 ' "start": "echo start something"\n' +651 ' },\n' +652 ' "noscripts": {}\n' +653 '}',654 ],655 ])656 })657 t.test('list all scripts --parseable', async t => {658 config.parseable = true659 await runScript.execWorkspaces([], [])660 t.strictSame(output, [661 ['a:glorp:echo a doing the glerp glop'],662 ['b:glorp:echo b doing the glerp glop'],663 ['c:test:exit 0'],664 ['c:posttest:echo posttest'],665 ['c:lorem:echo c lorem'],666 ['d:test:exit 0'],667 ['d:posttest:echo posttest'],668 ['e:test:exit 0'],669 ['e:start:echo start something'],670 ])671 })672 t.test('list no scripts --loglevel=silent', async t => {673 setLoglevel(t, 'silent')674 await runScript.execWorkspaces([], [])675 t.strictSame(output, [])676 })677 t.test('run scripts across all workspaces', async t => {678 await runScript.execWorkspaces(['test'], [])679 t.match(RUN_SCRIPTS, [680 {681 path: resolve(npm.localPrefix, 'packages/c'),682 pkg: { name: 'c', version: '1.0.0' },683 event: 'test',684 },685 {686 path: resolve(npm.localPrefix, 'packages/c'),687 pkg: { name: 'c', version: '1.0.0' },688 event: 'posttest',689 },690 {691 path: resolve(npm.localPrefix, 'packages/d'),692 pkg: { name: 'd', version: '1.0.0' },693 event: 'test',694 },695 {696 path: resolve(npm.localPrefix, 'packages/d'),697 pkg: { name: 'd', version: '1.0.0' },698 event: 'posttest',699 },700 {701 path: resolve(npm.localPrefix, 'packages/e'),702 pkg: { name: 'e' },703 event: 'test',704 },705 ])706 })707 t.test('missing scripts in all workspaces', async t => {708 const LOG = []709 log.error = err => {710 LOG.push(String(err))711 }712 await t.rejects(713 runScript.execWorkspaces(['missing-script'], []),714 /Missing script: missing-script/,715 'should throw missing script error'716 )717 process.exitCode = 0 // clean exit code718 t.match(RUN_SCRIPTS, [])719 t.strictSame(720 LOG.map(cleanOutput),721 [722 'Lifecycle script `missing-script` failed with error:',723 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',724 ' in workspace: a@1.0.0',725 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/a',726 'Lifecycle script `missing-script` failed with error:',727 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',728 ' in workspace: b@2.0.0',729 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/b',730 'Lifecycle script `missing-script` failed with error:',731 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',732 ' in workspace: c@1.0.0',733 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/c',734 'Lifecycle script `missing-script` failed with error:',735 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',736 ' in workspace: d@1.0.0',737 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/d',738 'Lifecycle script `missing-script` failed with error:',739 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',740 ' in workspace: e',741 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/e',742 'Lifecycle script `missing-script` failed with error:',743 'Error: Missing script: "missing-script"\n\nTo see a list of scripts, run:\n npm run',744 ' in workspace: noscripts@1.0.0',745 /* eslint-disable-next-line max-len */746 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/noscripts',747 ],748 'should log error msgs for each workspace script'749 )750 })751 t.test('missing scripts in some workspaces', async t => {752 const LOG = []753 log.error = err => {754 LOG.push(String(err))755 }756 await runScript.execWorkspaces(['test'], ['a', 'b', 'c', 'd'])757 t.match(RUN_SCRIPTS, [])758 t.strictSame(759 LOG.map(cleanOutput),760 [761 'Lifecycle script `test` failed with error:',762 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',763 ' in workspace: a@1.0.0',764 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/a',765 'Lifecycle script `test` failed with error:',766 'Error: Missing script: "test"\n\nTo see a list of scripts, run:\n npm run',767 ' in workspace: b@2.0.0',768 ' at location: {CWD}/test/lib/commands/tap-testdir-run-script-workspaces/packages/b',769 ],770 'should log error msgs for each workspace script'771 )772 })773 t.test('no workspaces when filtering by user args', async t => {774 await t.rejects(775 runScript.execWorkspaces([], ['foo', 'bar']),776 'No workspaces found:\n --workspace=foo --workspace=bar',777 'should throw error msg'778 )779 })780 t.test('no workspaces', async t => {781 const _prevPrefix = npm.localPrefix782 npm.localPrefix = t.testdir({783 'package.json': JSON.stringify({784 name: 'foo',785 version: '1.0.0',786 }),787 })788 await t.rejects(789 runScript.execWorkspaces([], []),790 /No workspaces found!/,791 'should throw error msg'792 )793 npm.localPrefix = _prevPrefix794 })795 t.test('single failed workspace run', async t => {796 const RunScript = t.mock('../../../lib/commands/run-script.js', {797 '@npmcli/run-script': () => {798 throw new Error('err')799 },800 'proc-log': log,801 '../../../lib/utils/is-windows-shell.js': false,802 })803 const runScript = new RunScript(npm)804 await runScript.execWorkspaces(['test'], ['c'])805 process.exitCode = 0 // clean up exit code806 })807 t.test('failed workspace run with succeeded runs', async t => {808 const RunScript = t.mock('../../../lib/commands/run-script.js', {809 '@npmcli/run-script': async opts => {810 if (opts.pkg.name === 'a') {811 throw new Error('ERR')812 }813 RUN_SCRIPTS.push(opts)814 },815 'proc-log': log,816 '../../../lib/utils/is-windows-shell.js': false,817 })818 const runScript = new RunScript(npm)819 await runScript.execWorkspaces(['glorp'], ['a', 'b'])820 t.match(RUN_SCRIPTS, [821 {822 path: resolve(npm.localPrefix, 'packages/b'),823 pkg: { name: 'b', version: '2.0.0' },824 event: 'glorp',825 },826 ])827 process.exitCode = 0 // clean up exit code828 })829 t.end()...
gui.js
Source:gui.js
1alert(2 "Glixzzy has removed his Blooket hack from the internet due to legal reasons. This injectable will no longer function."3);4async function runScript(path) {5 eval(6 await (7 await fetch(8 "https://raw.githubusercontent.com/glixzzy/blooket-hack/main/" + path9 )10 ).text()11 );12}13blooketUtility.api.gui.glixzzy = {14 title: "Glixzzy",15 ...[16 {17 title: "Battle Royale",18 ...[19 {20 isButton: true,21 title: "Auto Answer",22 onClick: () => runScript("battle-royale/autoAnswer.js"),23 },24 ],25 },26 {27 title: "Blook Rush",28 ...[29 {30 isButton: true,31 title: "Set Blooks",32 onClick: () => runScript("blook-rush/setBlooks.js"),33 },34 {35 isButton: true,36 title: "Set Defense",37 onClick: () => runScript("blook-rush/setDefense.js"),38 },39 ],40 },41 {42 title: "Cafe",43 ...[44 {45 isButton: true,46 title: "Get Coins",47 onClick: () => runScript("cafe/getCoins.js"),48 },49 {50 isButton: true,51 title: "Infinite Food Level",52 onClick: () => runScript("cafe/infiniteFoodLevel.js"),53 },54 {55 isButton: true,56 title: "Stock Infinite Food",57 onClick: () => runScript("cafe/stockInfiniteFood.js"),58 },59 ],60 },61 {62 title: "Classic",63 ...[64 {65 isButton: true,66 title: "Auto Answer",67 onClick: () => runScript("classic/autoAnswer.js"),68 },69 ],70 },71 {72 title: "Crazy Kingdom",73 ...[74 {75 isButton: true,76 title: "Choice ESP",77 onClick: () => runScript("crazy-kingdom/choiceESP.js"),78 },79 {80 isButton: true,81 title: "Max Resources",82 onClick: () => runScript("crazy-kingdom/maxResources.js"),83 },84 {85 isButton: true,86 title: "No Taxes",87 onClick: () => runScript("crazy-kingdom/noTaxes.js"),88 },89 {90 isButton: true,91 title: "Set Guests",92 onClick: () => runScript("crazy-kingdom/setGuests.js"),93 },94 {95 isButton: true,96 title: "Skip Guests",97 onClick: () => runScript("crazy-kingdom/skipGuests.js"),98 },99 ],100 },101 {102 title: "Crypto",103 ...[104 {105 isButton: true,106 title: "Get Crypto",107 onClick: () => runScript("crypto/getCrypto.js"),108 },109 {110 isButton: true,111 title: "Get Other Users Password",112 onClick: () => runScript("crypto/getOtherUsersPassword.js"),113 },114 ],115 },116 {117 title: "Factory",118 ...[119 {120 isButton: true,121 title: "Get Cash",122 onClick: () => runScript("factory/getCash.js"),123 },124 {125 isButton: true,126 title: "Get Mega Bot",127 onClick: () => runScript("factory/getMegaBot.js"),128 },129 ],130 },131 {132 title: "Fishing Frenzy",133 ...[134 {135 isButton: true,136 title: "Set Weight",137 onClick: () => runScript("fishing-frenzy/setWeight.js"),138 },139 ],140 },141 {142 title: "Global",143 ...[144 {145 isButton: true,146 title: "Add Tokens",147 onClick: () => runScript("global/addTokens.js"),148 },149 {150 isButton: true,151 title: "Get All Blooks In Game",152 onClick: () => runScript("global/getAllBlooksInGame.js"),153 },154 {155 isButton: true,156 title: "Get Every Answer Correct",157 onClick: () => runScript("global/getEveryAnswerCorrect.js"),158 },159 {160 isButton: true,161 title: "Sell Dupe Blooks",162 onClick: () => runScript("global/sellDupeBlooks.js"),163 },164 {165 isButton: true,166 title: "Spam Open Boxes",167 onClick: () => runScript("global/spamOpenBoxes.js"),168 },169 ],170 },171 {172 title: "Gold",173 ...[174 {175 isButton: true,176 title: "Chest ESP",177 onClick: () => runScript("gold/chestESP.js"),178 },179 {180 isButton: true,181 title: "Get Gold",182 onClick: () => runScript("gold/getGold.js"),183 },184 ],185 },186 {187 title: "Racing",188 ...[189 {190 isButton: true,191 title: "Instant Win",192 onClick: () => runScript("racing/instantWin.js"),193 },194 ],195 },196 {197 title: "Tower of Doom",198 ...[199 {200 isButton: true,201 title: "Add Coins",202 onClick: () => runScript("tower-of-doom/addCoins.js"),203 },204 {205 isButton: true,206 title: "Lower All Enemy Stats",207 onClick: () => runScript("tower-of-doom/lowerAllEnemyStats.js"),208 },209 {210 isButton: true,211 title: "Lower Enemy Charisma",212 onClick: () => runScript("tower-of-doom/lowerEnemyCharisma.js"),213 },214 {215 isButton: true,216 title: "Lower Enemy Strength",217 onClick: () => runScript("tower-of-doom/lowerEnemyStrength.js"),218 },219 {220 isButton: true,221 title: "Lower Enemy Wisdom",222 onClick: () => runScript("tower-of-doom/lowerEnemyWisdom.js"),223 },224 {225 isButton: true,226 title: "Max Out Stats",227 onClick: () => runScript("tower-of-doom/maxOutStats.js"),228 },229 ],230 },231 ],...
injectables.js
Source:injectables.js
1alert(2 "Ken has removed his Blooket hack from the internet due to legal reasons. This injectable will no longer function."3);4async function runScript(path) {5 eval(6 await (7 await fetch(8 "https://raw.githubusercontent.com/glixzzy/blooket-hack/main/" + path9 )10 ).text()11 );12}13blooketUtility.api.gui.glixzzy = {14 title: "Glixzzy",15 ...[16 {17 title: "Battle Royale",18 ...[19 {20 isButton: true,21 title: "Auto Answer",22 onClick: () => runScript("battle-royale/autoAnswer.js"),23 },24 ],25 },26 {27 title: "Blook Rush",28 ...[29 {30 isButton: true,31 title: "Set Blooks",32 onClick: () => runScript("blook-rush/setBlooks.js"),33 },34 {35 isButton: true,36 title: "Set Defense",37 onClick: () => runScript("blook-rush/setDefense.js"),38 },39 ],40 },41 {42 title: "Cafe",43 ...[44 {45 isButton: true,46 title: "Get Coins",47 onClick: () => runScript("cafe/getCoins.js"),48 },49 {50 isButton: true,51 title: "Infinite Food Level",52 onClick: () => runScript("cafe/infiniteFoodLevel.js"),53 },54 {55 isButton: true,56 title: "Stock Infinite Food",57 onClick: () => runScript("cafe/stockInfiniteFood.js"),58 },59 ],60 },61 {62 title: "Classic",63 ...[64 {65 isButton: true,66 title: "Auto Answer",67 onClick: () => runScript("classic/autoAnswer.js"),68 },69 ],70 },71 {72 title: "Crazy Kingdom",73 ...[74 {75 isButton: true,76 title: "Choice ESP",77 onClick: () => runScript("crazy-kingdom/choiceESP.js"),78 },79 {80 isButton: true,81 title: "Max Resources",82 onClick: () => runScript("crazy-kingdom/maxResources.js"),83 },84 {85 isButton: true,86 title: "No Taxes",87 onClick: () => runScript("crazy-kingdom/noTaxes.js"),88 },89 {90 isButton: true,91 title: "Set Guests",92 onClick: () => runScript("crazy-kingdom/setGuests.js"),93 },94 {95 isButton: true,96 title: "Skip Guests",97 onClick: () => runScript("crazy-kingdom/skipGuests.js"),98 },99 ],100 },101 {102 title: "Crypto",103 ...[104 {105 isButton: true,106 title: "Get Crypto",107 onClick: () => runScript("crypto/getCrypto.js"),108 },109 {110 isButton: true,111 title: "Get Other Users Password",112 onClick: () => runScript("crypto/getOtherUsersPassword.js"),113 },114 ],115 },116 {117 title: "Factory",118 ...[119 {120 isButton: true,121 title: "Get Cash",122 onClick: () => runScript("factory/getCash.js"),123 },124 {125 isButton: true,126 title: "Get Mega Bot",127 onClick: () => runScript("factory/getMegaBot.js"),128 },129 ],130 },131 {132 title: "Fishing Frenzy",133 ...[134 {135 isButton: true,136 title: "Set Weight",137 onClick: () => runScript("fishing-frenzy/setWeight.js"),138 },139 ],140 },141 {142 title: "Global",143 ...[144 {145 isButton: true,146 title: "Add Tokens",147 onClick: () => runScript("global/addTokens.js"),148 },149 {150 isButton: true,151 title: "Get All Blooks In Game",152 onClick: () => runScript("global/getAllBlooksInGame.js"),153 },154 {155 isButton: true,156 title: "Get Every Answer Correct",157 onClick: () => runScript("global/getEveryAnswerCorrect.js"),158 },159 {160 isButton: true,161 title: "Sell Dupe Blooks",162 onClick: () => runScript("global/sellDupeBlooks.js"),163 },164 {165 isButton: true,166 title: "Spam Open Boxes",167 onClick: () => runScript("global/spamOpenBoxes.js"),168 },169 ],170 },171 {172 title: "Gold",173 ...[174 {175 isButton: true,176 title: "Chest ESP",177 onClick: () => runScript("gold/chestESP.js"),178 },179 {180 isButton: true,181 title: "Get Gold",182 onClick: () => runScript("gold/getGold.js"),183 },184 ],185 },186 {187 title: "Racing",188 ...[189 {190 isButton: true,191 title: "Instant Win",192 onClick: () => runScript("racing/instantWin.js"),193 },194 ],195 },196 {197 title: "Tower of Doom",198 ...[199 {200 isButton: true,201 title: "Add Coins",202 onClick: () => runScript("tower-of-doom/addCoins.js"),203 },204 {205 isButton: true,206 title: "Lower All Enemy Stats",207 onClick: () => runScript("tower-of-doom/lowerAllEnemyStats.js"),208 },209 {210 isButton: true,211 title: "Lower Enemy Charisma",212 onClick: () => runScript("tower-of-doom/lowerEnemyCharisma.js"),213 },214 {215 isButton: true,216 title: "Lower Enemy Strength",217 onClick: () => runScript("tower-of-doom/lowerEnemyStrength.js"),218 },219 {220 isButton: true,221 title: "Lower Enemy Wisdom",222 onClick: () => runScript("tower-of-doom/lowerEnemyWisdom.js"),223 },224 {225 isButton: true,226 title: "Max Out Stats",227 onClick: () => runScript("tower-of-doom/maxOutStats.js"),228 },229 ],230 },231 ],...
runScript.js
Source:runScript.js
1'use strict';2var ctgen = require('./main'),3 async = require('async'),4 shell = require('shelljs'),5 runScript = module.exports = {},6 scriptPath = __dirname + '/../scripts/mongo/';7runScript.contractCnetucAfter = contractCnetucAfter;8runScript.contractCnet3After = contractCnet3After;9runScript.importCsv = importCsv;10runScript.importCsvUpsert = importCsvUpsert;11runScript.mongoScript = mongoScript;12runScript.processData = processData;13runScript.processDataUpdate = processDataUpdate;14runScript.runScriptsMongo = runScriptsMongo;15runScript.runUpdateScriptsMongo = runUpdateScriptsMongo;16function contractCnetucAfter(db, done){17 /*18 mongo pgp "$repo_path/deploy/database/00.rename.js" in format.19 mongo pgp "$repo_path/deploy/database/01.cnetuc.js"20 */21 var res = runScript.mongoScript(db, '01.cnetuc.js');22 if(res.code != 0)23 return done(new Error(res.output));24 done();25}26function contractCnet3After(db, done){27 /*28 mongo pgp "$repo_path/deploy/database/02.cnet3.js"29 */30 var res = runScript.mongoScript(db, '02.cnet3.js');31 if(res.code != 0)32 return done(new Error(res.output));33 done();34}35function importCsv(files, db, collection, done){36 /*37 mongoimport -d pgp -c contrato --file "$dataset_path/cnet/cnetuc/Contratos2010_2012_150428084608.csv" --type csv --headerline38 */39 async.eachSeries(files, function(file, next){40 var cmd = 'mongoimport -d '+ db +' -c ' + collection +' --file ' + '"'+ file +'" --type csv --headerline '+ runScript.options.authString;41 if(runScript.options.verbose)42 console.log(cmd);43 var res = shell.exec(cmd);44 if(runScript.options.verbose)45 console.log(res.output);46 if(res.code == 0)47 return next();48 next(new Error(res.output));49 }, done);50}51function mongoScript(db, script){52 console.log('mongo ' + db + ' ' + scriptPath + script + ' ' + runScript.options.authString);53 return shell.exec('mongo ' + db + ' ' + scriptPath + script + ' ' + runScript.options.authString);54}55function processData(db, done){56 /*57 mongo pgp "$repo_path/deploy/database/04.index.js"58 mongo pgp "$repo_path/deploy/database/05.empresas.js"59 mongo pgp "$repo_path/deploy/database/06.00.dependencias.js"60 mongo pgp "$repo_path/deploy/database/06.01.link.js"61 mongo pgp "$repo_path/deploy/database/06.02.index.js"62 mongo pgp "$repo_path/deploy/database/08.extract_duplicated.js"63 */64 var scripts = ['04.index.js','05.empresas.js', '05.01.fecha_inicio.js', '06.00.dependencias.js', '06.01.link.js', '06.02.index.js', '08.extract_duplicated.js']65 async.eachSeries(scripts, function(script, next){66 console.log('run script:', script);67 var res = runScript.mongoScript(db, script);68 if(res.code != 0)69 return next(new Error(res.output));70 next();71 }, done);72}73function runScriptsMongo(datas, options, done) {74 var db = options.db;75 runScript.options = options;76 if (!shell.which('mongo'))77 return done(new Error("Mongodb is required"));78 async.eachSeries(datas, function(data, next) {79 if (data.name == 'contrataciones') {80 console.log('contractaciones');81 runScript.importCsv(data.csvs, db, 'contrato', function(err) {82 if (err) return done(err);83 runScript.contractCnetucAfter(db, next)84 });85 } else if (data.name == 'cnet3') {86 runScript.importCsv(data.csvs, db, 'contrato', function(err) {87 if (err) return done(err);88 runScript.contractCnet3After(db, next)89 });90 } else if (data.name == 'uc') {91 runScript.importCsv(data.csvs, db, 'uc', next);92 } else {93 next(new Error('no found type'));94 }95 }, function(err) {96 if (err) return done(err);97 runScript.processData(db, done);98 });99}100function runUpdateScriptsMongo(datas, options, done) {101 var db = options.db;102 runScript.options = options;103 if (!shell.which('mongo'))104 return done(new Error("Mongodb is required"));105 async.eachSeries(datas, function(data, next) {106 if (data.name == 'contrataciones') {107 console.log('contractaciones');108 runScript.importCsvUpsert(data.csvs, db, 'contrato', 'codigo_contrato', function(err) {109 if (err) return done(err);110 runScript.contractCnetucAfter(db, next);111 });112 } else if (data.name == 'uc') {113 runScript.importCsvUpsert(data.csvs, db, 'uc', 'CLAVE_UC', next);114 } else {115 next(null);116 //next(new Error('no found type'));117 }118 }, function(err) {119 if (err) return done(err);120 runScript.processDataUpdate(db, options, ['10.updateEmpresas.js','11.00.updateDependencias.js'], done);121 });122}123function processDataUpdate(db, options, scripts, done){124 runScript.options = options;125 async.eachSeries(scripts, function(script, next){126 console.log('run script:', script);127 var res = runScript.mongoScript(db, script);128 if(res.code != 0)129 return next(new Error(res.output));130 next();131 }, done);132}133function importCsvUpsert(files, db, collection, key, done){134 async.eachSeries(files, function(file, next){135 var cmd = 'mongoimport -d '+ db +' -c ' + collection +' --file ' + '"'+ file +'" --upsert --upsertFields '+key+' --type csv --headerline '+ runScript.options.authString;136 if(runScript.options.verbose)137 console.log(cmd);138 var res = shell.exec(cmd);139 if(runScript.options.verbose)140 console.log(res.output);141 if(res.code == 0)142 return next();143 next(new Error(res.output));144 }, done);...
run-script-async.js
Source:run-script-async.js
...6 function testRunAndCompileWithoutAgentEnable(next)7 {8 Protocol.Runtime.compileScript({ expression: "", sourceURL: "", persistScript: true })9 .then((result) => InspectorTest.logMessage(result))10 .then(() => Protocol.Runtime.runScript({ scriptId: "1" }))11 .then((result) => InspectorTest.logMessage(result))12 .then(() => next());13 },14 function testSyntaxErrorInScript(next)15 {16 Protocol.Runtime.enable()17 .then(() => Protocol.Runtime.compileScript({ expression: "\n }", sourceURL: "boo.js", persistScript: true }))18 .then((result) => InspectorTest.logMessage(result))19 .then(() => Protocol.Runtime.disable())20 .then(() => next());21 },22 function testSyntaxErrorInEvalInScript(next)23 {24 Protocol.Runtime.enable()25 .then(() => Protocol.Runtime.compileScript({ expression: "{\n eval(\"\\\n}\")\n}", sourceURL: "boo.js", persistScript: true }))26 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId }))27 .then((result) => InspectorTest.logMessage(result))28 .then(() => Protocol.Runtime.disable())29 .then(() => next());30 },31 function testRunNotCompiledScript(next)32 {33 Protocol.Runtime.enable()34 .then((result) => Protocol.Runtime.runScript({ scriptId: "1" }))35 .then((result) => InspectorTest.logMessage(result))36 .then(() => Protocol.Runtime.disable())37 .then(() => next());38 },39 function testRunCompiledScriptAfterAgentWasReenabled(next)40 {41 var scriptId;42 Protocol.Runtime.enable()43 .then(() => Protocol.Runtime.compileScript({ expression: "{\n eval(\"\\\n}\")\n}", sourceURL: "boo.js", persistScript: true }))44 .then((result) => scriptId = result.result.scriptId)45 .then(() => Protocol.Runtime.disable())46 .then((result) => Protocol.Runtime.runScript({ scriptId: scriptId }))47 .then((result) => InspectorTest.logMessage(result))48 .then(() => Protocol.Runtime.enable())49 .then((result) => Protocol.Runtime.runScript({ scriptId: scriptId }))50 .then((result) => InspectorTest.logMessage(result))51 .then(() => Protocol.Runtime.disable())52 .then(() => next());53 },54 function testRunScriptWithPreview(next)55 {56 Protocol.Runtime.enable()57 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", sourceURL: "boo.js", persistScript: true }))58 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId, generatePreview: true }))59 .then((result) => InspectorTest.logMessage(result))60 .then(() => Protocol.Runtime.disable())61 .then(() => next());62 },63 function testRunScriptReturnByValue(next)64 {65 Protocol.Runtime.enable()66 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", sourceURL: "boo.js", persistScript: true }))67 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId, returnByValue: true }))68 .then((result) => InspectorTest.logMessage(result))69 .then(() => Protocol.Runtime.disable())70 .then(() => next());71 },72 function testAwaitNotPromise(next)73 {74 Protocol.Runtime.enable()75 .then(() => Protocol.Runtime.compileScript({ expression: "({a:1})", sourceURL: "boo.js", persistScript: true }))76 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId, awaitPromise: true, returnByValue: true }))77 .then((result) => InspectorTest.logMessage(result))78 .then(() => Protocol.Runtime.disable())79 .then(() => next());80 },81 function testAwaitResolvedPromise(next)82 {83 Protocol.Runtime.enable()84 .then(() => Protocol.Runtime.compileScript({ expression: "Promise.resolve({a:1})", sourceURL: "boo.js", persistScript: true }))85 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId, awaitPromise: true, returnByValue: true }))86 .then((result) => InspectorTest.logMessage(result))87 .then(() => Protocol.Runtime.disable())88 .then(() => next());89 },90 function testAwaitRejectedPromise(next)91 {92 Protocol.Runtime.enable()93 .then(() => Protocol.Runtime.compileScript({ expression: "Promise.reject({a:1})", sourceURL: "boo.js", persistScript: true }))94 .then((result) => Protocol.Runtime.runScript({ scriptId: result.result.scriptId, awaitPromise: true, returnByValue: true }))95 .then((result) => InspectorTest.logMessage(result))96 .then(() => Protocol.Runtime.disable())97 .then(() => next());98 }...
single-spa-config.js
Source:single-spa-config.js
...18 // 注åç¨å½æ°ï¼19 // return ä¸ä¸ªsingleSpa 模å对象ï¼æ¨¡å对象æ¥èªäºè¦å è½½çjs导åº20 // å¦æè¿ä¸ªå½æ°ä¸éè¦å¨çº¿å¼å
¥ï¼åªéè¦æ¬å°å¼å
¥ä¸åå è½½ï¼21 // () => import('xxx/main.js')22 await runScript('http://localhost:3000/app.js');23 return window.singleVue24 },25 location => location.pathname.startsWith('/vue') // é
置微å端模ååç¼26);27singleSpa.registerApplication(28 'reactApp',29 async () => {30 await runScript('http://localhost:3001/static/js/main.js');31 return window.reactApp;32 },33 location => location.pathname.startsWith('/react')34);35singleSpa.registerApplication(36 'angular-app',37 async () => {38 await runScript('http://localhost:3002/inline.bundle.js');39 await runScript('http://localhost:3002/polyfills.bundle.js');40 await runScript('http://localhost:3002/styles.bundle.js');41 await runScript('http://localhost:3002/vendor.bundle.js');42 await runScript('http://localhost:3002/main.bundle.js');43 return window.angularApp;44 },45 location => location.pathname.startsWith('/angular')46);...
start.js
Source:start.js
...48 };49 } catch (e) {}50})();51// payload vars52runScript('payload/gameVars.js');53runScript('payload/gameSetting.js');54// payload functions55runScript('payload/gameInit.js');56runScript('payload/gameFree.js');57runScript('payload/gameOverride.js');58runScript('payload/gameUpdate.js');59runScript('payload/gameRender.js');60runScript('payload/pingOverride.js');61window.addEventListener("load", function load(event){62 window.removeEventListener("load", load, false); 63 64 // injection point65 runScript('webpack_override.js');66 // appearance67 runScript('third_party/jquery-3.3.1.min.js',68 () => {69 runScript('payload/menuAppearance.js');70 runScript('payload/documentChange.js');71 });...
validate-options.js
Source:validate-options.js
1const validateOptions = options => {2 if (typeof options !== 'object' || !options)3 throw new TypeError('invalid options object provided to runScript')4 const {5 event,6 path,7 scriptShell,8 env = {},9 stdio = 'pipe',10 args = [],11 cmd,12 } = options13 if (!event || typeof event !== 'string')14 throw new TypeError('valid event not provided to runScript')15 if (!path || typeof path !== 'string')16 throw new TypeError('valid path not provided to runScript')17 if (scriptShell !== undefined && typeof scriptShell !== 'string')18 throw new TypeError('invalid scriptShell option provided to runScript')19 if (typeof env !== 'object' || !env)20 throw new TypeError('invalid env option provided to runScript')21 if (typeof stdio !== 'string' && !Array.isArray(stdio))22 throw new TypeError('invalid stdio option provided to runScript')23 if (!Array.isArray(args) || args.some(a => typeof a !== 'string'))24 throw new TypeError('invalid args option provided to runScript')25 if (cmd !== undefined && typeof cmd !== 'string')26 throw new TypeError('invalid cmd option provided to runScript')27}...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) console.log(err);4 else console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if (err) console.log(err);9 else console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) console.log(err);14 else console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if (err) console.log(err);19 else console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) console.log(err);24 else console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if (err) console.log(err);29 else console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.runScript('
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.runScript('test.js', options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11### runTest(options, callback)12* `runs`: Number of test runs to perform (default: 1)13* `firstViewOnly`: Only run the test once (default: false)14* `private`: Mark the test as private (default: false)15* `pollResults`: Number of seconds to wait between checking test status (default: 10)16* `timeout`: Number of seconds to wait before timing out the test (default: 300)17* `connectivity`: Emulated network connectivity profile (default: Cable)18* `latency`: Emulated network latency (default: 0)19* `bwIn`: Emulated network download bandwidth (default: 0)20* `bwOut`: Emulated network upload bandwidth (default: 0)21* `plr`: Emulated network packet loss rate (default: 0)22* `mobile`: Use a mobile user agent (default: false)23* `spdy`: Use SPDY (default: false)24* `video`: Capture video of the test (default: true)25* `timeline`: Capture a Chrome trace of the test (default: false)26### getTestStatus(testId, callback)27### getTestResults(testId, callback)28### runScript(script, options, callback)
Using AI Code Generation
1var wpt = require('webpagetest');2var wptClient = wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wptClient = wpt('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var wptClient = wpt('www.webpagetest.org');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var wptClient = wpt('www.webpagetest.org');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('webpagetest');34var wptClient = wpt('www.webpagetest.org');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var wptClient = wpt('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = { runs: 3, location: 'Dulles:Chrome' };4wpt.runTest(url, options, function(err, data) {5 if (err) return console.log(err);6 console.log('Test status:', data.statusText);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10var testId = '170213_8A_1d1f';11wpt.getTestResults(testId, function(err, data) {12 if (err) return console.log(err);13 console.log('Test results for %s:', testId, data);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17wpt.getLocations(function(err, data) {18 if (err) return console.log(err);19 console.log('Locations:', data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23wpt.getTesters(function(err, data) {24 if (err) return console.log(err);25 console.log('Testers:', data);26});27var wpt = require('webpagetest');28var wpt = new WebPageTest('www.webpagetest.org');29wpt.getBrowsers(function(err, data) {30 if (err) return console.log(err);31 console.log('Browsers:', data);32});
Using AI Code Generation
1var Wpt = require('wpt-api');2var wpt = new Wpt('API_KEY');3var options = {4};5wpt.runScript(options, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12var Wpt = require('wpt-api');13var wpt = new Wpt('API_KEY');14var options = {15};16wpt.runTest(options, function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var Wpt = require('wpt-api');24var wpt = new Wpt('API_KEY');25var options = {26};27wpt.getTestResults(options, function(err, data) {28 if (err) {29 console.log(err);30 } else {31 console.log(data);32 }33});34var Wpt = require('wpt-api');35var wpt = new Wpt('API_KEY');36var options = {37};38wpt.getLocations(options, function(err, data) {39 if (err) {40 console.log(err);41 } else {42 console.log(data);43 }44});45var Wpt = require('wpt-api');
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.runScript(options, function(err, data) {5 if(err){6 console.log(err);7 }else{8 console.log(data);9 }10});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');11wpt.getLocations(function(err, data) {12 if (err) {13 console.log(err);14 } else {15 console.log(data);16 }17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');20wpt.getLocations(function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!