How to use capture.stop method in qawolf

Best JavaScript code snippet using qawolf

_suite.js

Source:_suite.js Github

copy

Full Screen

1const os = require('os');2const fs = require('fs-extra');3const path = require('path');4const assert = require('assert');5const semver = require('semver');6const btools = require('../index');7// @ts-ignore8const thisPackage = require('../package.json');9if (btools.TerminalCanBlock) {10 console.log('\u001b[2J'); // clear screen11}12console.log(`${os.EOL}Running Mocha Test Suite ...`);13describe(`${thisPackage.name} read-only properties`, function () {14 it('should be listed accurately', (done) => {15 var table = [];16 btools.ReadOnlyProperties.forEach(prop => {17 console.log(` ${prop}\t= ${btools[prop]}\t(${typeof (btools[prop])})`);18 table.push({ name: prop, value: btools[prop], type: typeof (btools[prop]) });19 });20 done();21 });22});23describe(`${thisPackage.name} Console tests`, function () {24 it('ConsoleLogLevel.Validate() should succeed', done => {25 /** @type {import('../index').ConsoleOptions} */26 var consoleOptions;27 consoleOptions = btools.ConsoleLogLevel.Validate({ logLevel: 'default' });28 assert.strictEqual(consoleOptions.verbose, false, '\'verbose\' should have value');29 assert.strictEqual(consoleOptions.debug, false, '\'debug\' should have value');30 consoleOptions = btools.ConsoleLogLevel.Validate({ logLevel: 'verbose' });31 assert.strictEqual(consoleOptions.verbose, true, '\'verbose\' should have value');32 assert.strictEqual(consoleOptions.debug, false, '\'debug\' should have value');33 consoleOptions = btools.ConsoleLogLevel.Validate({ logLevel: 'debug' });34 assert.strictEqual(consoleOptions.verbose, true, '\'verbose\' should have value');35 assert.strictEqual(consoleOptions.debug, true, '\'debug\' should have value');36 consoleOptions = btools.ConsoleLogLevel.Validate({ logLevel: 'default', verbose: true });37 assert.strictEqual(consoleOptions.verbose, true, '\'verbose\' should have value');38 assert.strictEqual(consoleOptions.debug, false, '\'debug\' should have value');39 consoleOptions = btools.ConsoleLogLevel.Validate({ logLevel: 'default', debug: true });40 assert.strictEqual(consoleOptions.verbose, false, '\'verbose\' should have value');41 assert.strictEqual(consoleOptions.debug, true, '\'debug\' should have value');42 done();43 });44 it('Line continuation should succeed', done => {45 btools.ConsoleCaptureStart();46 try {47 console.info('Line to complete\b');48 console.info('\bon next call.');49 console.warn('Warning composed\b');50 console.warn('\bby more than\b');51 console.warn('\btwo calls.');52 btools.ConsoleCaptureStop();53 } catch (err) {54 btools.ConsoleCaptureStop();55 throw err;56 }57 assert.strictEqual(btools.stdout.length, 5, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);58 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);59 done();60 });61 btools.ConsoleSupportedPlatforms.forEach(platform => {62 it(`should succeed for platform '${platform}'`, function (done) {63 btools.ConsoleCaptureStart();64 try {65 // @ts-ignore66 btools.ConsoleInit(platform);67 btools.ConsoleCaptureStop();68 } catch (err) {69 btools.ConsoleCaptureStop();70 throw err;71 }72 btools.ConsoleCaptureStart();73 try {74 btools.ConsoleDefaultMethods.forEach(method => {75 console[method](`Testing '${method}' message.`);76 });77 btools.ConsoleCaptureStop();78 } catch (err) {79 btools.ConsoleCaptureStop();80 throw err;81 }82 assert.strictEqual(btools.stdout.length, btools.DebugMode ? 3 : 2, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);83 assert.strictEqual(btools.stderr.length, 1, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);84 btools.ConsoleDefaultMethods.forEach(method => {85 var lines = [];86 var checkMessage = `Testing '${method}' message.${os.EOL}`;87 if (method === 'error') {88 btools.stderr.forEach(line => {89 // @ts-ignore90 lines.push(line.plain(method));91 });92 assert.ok(lines.includes(checkMessage), `stderr should include '${checkMessage}'`);93 } else {94 btools.stdout.forEach(line => {95 // @ts-ignore96 lines.push(line.plain(method));97 });98 if (method === 'debug' && !btools.DebugMode) {99 assert.ok(!lines.includes(checkMessage), `stdout shouldn't include '${checkMessage}'`);100 } else {101 assert.ok(lines.includes(checkMessage), `stdout should include '${checkMessage}'`);102 }103 }104 });105 done();106 });107 });108});109describe(`${thisPackage.name} vc-utils tests`, function () {110 var vc = require('../lib/vc-utils');111 it('GetLastChange() should fail with faulty path specification', function (done) {112 var result;113 btools.ConsoleCaptureStart();114 try {115 result = vc.GetLastChange('');116 assert.fail('should have failed');117 } catch (err) {118 btools.ConsoleCaptureStop();119 assert.ok(err instanceof Error, '\'err\' should be an Error object');120 assert.strictEqual(err.message, '\'\' is not a valid path specification for parameter \'pathSpec\'.', 'Error message should be');121 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');122 }123 done();124 });125 it('GetLastChange() should return NaN with unknown or untracked path specification', function (done) {126 var result;127 btools.ConsoleCaptureStart();128 try {129 result = vc.GetLastChange(path.resolve('fakefile'));130 btools.ConsoleCaptureStop();131 } catch (err) {132 btools.ConsoleCaptureStop();133 throw err;134 }135 assert.strictEqual(btools.stdout.length, btools.DebugMode ? 4 : 0, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);136 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);137 assert.ok(isNaN(result), 'Variable \'result\' should be NaN');138 done();139 });140 it('GetLastChange() should succeed otherwise', function (done) {141 var result;142 btools.ConsoleCaptureStart();143 try {144 result = vc.GetLastChange(path.resolve('.'));145 btools.ConsoleCaptureStop();146 } catch (err) {147 btools.ConsoleCaptureStop();148 throw err;149 }150 assert.strictEqual(btools.stdout.length, btools.DebugMode ? 4 : 0, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);151 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);152 assert.ok(!isNaN(result), 'Variable \'result\' should not be NaN');153 assert.strictEqual(typeof (result), 'number', 'Variable \'result\' should have exact type');154 done();155 });156 it('SupportedVersionControlProviders() should return specific list', function (done) {157 var result;158 btools.ConsoleCaptureStart();159 try {160 result = vc.SupportedVersionControlProviders();161 btools.ConsoleCaptureStop();162 } catch (err) {163 btools.ConsoleCaptureStop();164 throw err;165 }166 var expectedProviders = ['git', 'tfs'];167 var exceptions = [];168 try {169 assert.strictEqual(result.length, expectedProviders.length, 'result array should have exact length');170 } catch (err) {171 exceptions.push(err);172 }173 expectedProviders.forEach(provider => {174 try {175 assert.ok(result.includes(provider), `result array should include '${provider}'`);176 } catch (err) {177 exceptions.push(err);178 }179 });180 result.forEach(provider => {181 try {182 assert.ok(expectedProviders.includes(provider), `result array should NOT include provider '${provider}'`);183 } catch (err) {184 exceptions.push(err);185 }186 });187 if (exceptions.length > 0) {188 var msg = [];189 exceptions.forEach(err => msg.push(err.message));190 assert.fail(`Aggregate error, collected ${exceptions.length} errors total:${os.EOL}\t${msg.join(`${os.EOL}\t`)}`);191 }192 done();193 });194 it('GetVersionControlProvider() should return [undefined] if no VC provider was found', function (done) {195 var result;196 btools.ConsoleCaptureStart();197 try {198 result = vc.GetVersionControlProvider('../');199 btools.ConsoleCaptureStop();200 } catch (err) {201 btools.ConsoleCaptureStop();202 throw err;203 }204 assert.strictEqual(`${result}`, 'undefined', 'result should be');205 done();206 });207 it('GetVersionControlProvider() should succeed', function (done) {208 var result;209 btools.ConsoleCaptureStart();210 try {211 result = vc.GetVersionControlProvider();212 btools.ConsoleCaptureStop();213 } catch (err) {214 btools.ConsoleCaptureStop();215 throw err;216 }217 assert.strictEqual(`${result}`, 'git', 'result should be');218 done();219 });220});221describe(`${thisPackage.name} os-utils tests`, function () {222 it('ResolveEnv() should succeed for platform \'win32\'', function (done) {223 var envVarKeys = Object.keys(process.env);224 for (let index = 0; index < envVarKeys.length; index++) {225 if (process.env[envVarKeys[index]].indexOf('%') > 0) {226 continue;227 }228 if (process.env[envVarKeys[index]].indexOf('$') > 0) {229 continue;230 }231 var result;232 btools.ConsoleCaptureStart();233 try {234 result = btools.os.ResolveEnv(`%${envVarKeys[index]}%`, 'win32');235 btools.ConsoleCaptureStop();236 } catch (err) {237 btools.ConsoleCaptureStop();238 throw err;239 }240 assert.strictEqual(`${result}`, process.env[envVarKeys[index]], `result for environment variable #${index} ('${envVarKeys[index]}') should be`);241 }242 done();243 });244 it('ResolveEnv() should succeed for platform \'other\'', function (done) {245 var envVarKeys = Object.keys(process.env);246 for (let index = 0; index < envVarKeys.length; index++) {247 if (process.env[envVarKeys[index]].indexOf('%') > 0) {248 continue;249 }250 if (process.env[envVarKeys[index]].indexOf('$') > 0) {251 continue;252 }253 var result;254 btools.ConsoleCaptureStart();255 try {256 result = btools.os.ResolveEnv(`$${envVarKeys[index]}`, 'other');257 btools.ConsoleCaptureStop();258 } catch (err) {259 btools.ConsoleCaptureStop();260 throw err;261 }262 assert.strictEqual(`${result}`, process.env[envVarKeys[index]], `result for environment variable #${index} ('${envVarKeys[index]}') should be`);263 }264 done();265 });266 it('ResolvePath() should succeed with implicit limit 1 and no result', function (done) {267 var randomFile = Math.random().toString(36).substring(2, 15);268 var result;269 btools.ConsoleCaptureStart();270 try {271 result = btools.os.ResolvePath(randomFile, 1);272 btools.ConsoleCaptureStop();273 } catch (err) {274 btools.ConsoleCaptureStop();275 throw err;276 }277 assert.strictEqual(result, '', 'result should be');278 done();279 });280 it('ResolvePath() should succeed with implicit limit 1 and a result', function (done) {281 var result;282 btools.ConsoleCaptureStart();283 try {284 result = btools.os.ResolvePath('node');285 btools.ConsoleCaptureStop();286 } catch (err) {287 btools.ConsoleCaptureStop();288 throw err;289 }290 assert.strictEqual(result, process.execPath, 'result should be');291 done();292 });293 it('ResolvePath() should succeed with limit 0 and no result', function (done) {294 var randomFile = Math.random().toString(36).substring(2, 15);295 var result;296 btools.ConsoleCaptureStart();297 try {298 result = btools.os.ResolvePath(randomFile, 0);299 btools.ConsoleCaptureStop();300 } catch (err) {301 btools.ConsoleCaptureStop();302 throw err;303 }304 assert.ok(result.length === 0, 'result count should be');305 done();306 });307 it('ResolvePath() should succeed with limit 0 and a result', function (done) {308 var result;309 btools.ConsoleCaptureStart();310 try {311 result = btools.os.ResolvePath('node', 0);312 btools.ConsoleCaptureStop();313 } catch (err) {314 btools.ConsoleCaptureStop();315 throw err;316 }317 assert.ok(result.length > 0, 'result should not be empty');318 assert.strictEqual(result[0], process.execPath, 'result should be');319 done();320 });321 it('ListProperties() should list \'process\' properties accurately', (done) => {322 btools.os.ListProperties(process, { namePrefix: 'process', skipTypeOf: ['function'] }).forEach(prop => {323 console.debug(` ${prop}`);324 });325 done();326 });327 it('ListProperties() should list \'os\' properties accurately', (done) => {328 btools.os.ListProperties(os, { namePrefix: 'os', skipTypeOf: ['function'] }).forEach(prop => {329 console.debug(` ${prop}`);330 });331 done();332 });333});334describe(`${thisPackage.name} declaration-files tests`, function () {335 var deffiles = require('../lib/declaration-files');336 it('RemoveDeclarations() should succeed', function (done) {337 var result = 0;338 var expectedSubfolders = 3; // current status, may change339 btools.ConsoleCaptureStart();340 try {341 result = deffiles.RemoveDeclarations(undefined, { dryRun: true, consoleOptions: { logLevel: 'debug' } });342 btools.ConsoleCaptureStop();343 } catch (err) {344 btools.ConsoleCaptureStop();345 throw err;346 }347 assert.ok(btools.stdout.length > 0, 'stdout should contain lines');348 // @ts-ignore349 assert.strictEqual(btools.stdout[0].plain('info'), `Removing declaration files (*.d.ts) from path '${path.resolve('.')}' and ${expectedSubfolders} subfolders.${os.EOL}`, 'stdout first line should contain');350 // @ts-ignore351 assert.strictEqual(btools.stdout[btools.stdout.length - 1].plain('info'), `Removed ${result} declaration files (*.d.ts) from path '${path.resolve('.')}'.${os.EOL}`, 'stdout second line should contain');352 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);353 done();354 });355});356describe(`${thisPackage.name} AsciiDoc tests`, function () {357 var genadoc = require('../lib/generate-adoc');358 it('ResolveIncludes() should fail without proper root source path for include files', function (done) {359 var result;360 btools.ConsoleCaptureStart();361 try {362 // @ts-ignore363 result = genadoc.ResolveIncludes();364 assert.fail('should have failed');365 } catch (err) {366 btools.ConsoleCaptureStop();367 assert.ok(err instanceof Error, '\'err\' should be an Error object');368 assert.strictEqual(err.message, 'The root source path for include files \'undefined\' is not a directory.', 'Error message should be');369 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');370 }371 done();372 });373 it('ResolveIncludes() should succeed', function (done) {374 var fakeRoot = '.';375 var fakePath = 'fakePath';376 btools.ConsoleCaptureStart();377 try {378 genadoc.ResolveIncludes(fakeRoot, `include::${fakePath}[]include::${fakePath}[]`);379 btools.ConsoleCaptureStop();380 } catch (err) {381 btools.ConsoleCaptureStop();382 throw err;383 }384 assert.strictEqual(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);385 assert.strictEqual(btools.stderr.length, 2, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);386 // @ts-ignore387 assert.strictEqual(btools.stderr[0].plain('error'), `Include file '${path.resolve(fakeRoot, fakePath)}' could not be found.${os.EOL}`, 'stderr first line should contain');388 // @ts-ignore389 assert.strictEqual(btools.stderr[1].plain('error'), `Include file '${path.resolve(fakeRoot, fakePath)}' could not be found.${os.EOL}`, 'stderr second line should contain');390 done();391 });392 it('GetAttribute() should fail without attributeName specification', function (done) {393 var result;394 btools.ConsoleCaptureStart();395 try {396 // @ts-ignore397 result = genadoc.GetAttribute();398 assert.fail('should have failed');399 } catch (err) {400 btools.ConsoleCaptureStop();401 assert.ok(err instanceof Error, '\'err\' should be an Error object');402 assert.strictEqual(err.message, 'The \'attributeName\' parameter is not a string.', 'Error message should be');403 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');404 }405 done();406 });407 it('GetAttribute() should fail with duplicate attribute definitions', function (done) {408 var result;409 var attributeName = 'attributeName';410 var inputLines = [`:${attributeName}: `, `:${attributeName}: `];411 btools.ConsoleCaptureStart();412 try {413 result = genadoc.GetAttribute(attributeName, ...inputLines);414 assert.fail('should have failed');415 } catch (err) {416 btools.ConsoleCaptureStop();417 assert.ok(err instanceof Error, '\'err\' should be an Error object');418 assert.strictEqual(err.message, `Attribute '${attributeName}' has been defined multiple times.`, 'Error message should be');419 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');420 }421 done();422 });423 it('GetAttribute() should succeed otherwise', function (done) {424 var result;425 var attributeName = 'attributeName';426 var inputLines = [];427 btools.ConsoleCaptureStart();428 try {429 result = genadoc.GetAttribute('');430 result = genadoc.GetAttribute('', ...inputLines);431 btools.ConsoleCaptureStop();432 } catch (err) {433 btools.ConsoleCaptureStop();434 throw err;435 }436 assert.strictEqual(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);437 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);438 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');439 btools.ConsoleCaptureStart();440 try {441 result = genadoc.GetAttribute(attributeName, ...inputLines);442 btools.ConsoleCaptureStop();443 } catch (err) {444 btools.ConsoleCaptureStop();445 throw err;446 }447 assert.strictEqual(btools.stdout.length, 0, 'stdout shouldn\'t contain any lines');448 assert.strictEqual(btools.stderr.length, 0, 'stderr shouldn\'t contain any lines');449 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');450 inputLines = [`:${attributeName}:`];451 btools.ConsoleCaptureStart();452 try {453 result = genadoc.GetAttribute(attributeName, ...inputLines);454 btools.ConsoleCaptureStop();455 } catch (err) {456 btools.ConsoleCaptureStop();457 throw err;458 }459 assert.strictEqual(btools.stdout.length, 0, 'stdout shouldn\'t contain any lines');460 assert.strictEqual(btools.stderr.length, 0, 'stderr shouldn\'t contain any lines');461 assert.strictEqual(result, undefined, 'Variable \'result\' should have exact value');462 inputLines = [`:${attributeName}: `];463 btools.ConsoleCaptureStart();464 try {465 result = genadoc.GetAttribute(attributeName, ...inputLines);466 btools.ConsoleCaptureStop();467 } catch (err) {468 btools.ConsoleCaptureStop();469 throw err;470 }471 assert.strictEqual(btools.stdout.length, 0, 'stdout shouldn\'t contain any lines');472 assert.strictEqual(btools.stderr.length, 0, 'stderr shouldn\'t contain any lines');473 assert.strictEqual(result, '', 'Variable \'result\' should have exact value');474 done();475 });476 it('GenerateReadme() should succeed', function (done) {477 var packagePath = path.resolve('.');478 var readmeFileName = 'README.md';479 var readmeContent = '';480 var readmeFile = path.join(packagePath, readmeFileName);481 if (fs.existsSync(readmeFile)) {482 readmeContent = fs.readFileSync(readmeFile, { encoding: 'utf8' });483 }484 btools.ConsoleCaptureStart();485 try {486 genadoc.GenerateReadme(packagePath, readmeFileName, { updateTimestamp: true, noPackageJsonUpdate: true, outputFormat: 'md' });487 btools.ConsoleCaptureStop();488 } catch (err) {489 btools.ConsoleCaptureStop();490 throw err;491 } finally {492 if (readmeContent) {493 fs.writeFileSync(readmeFile, readmeContent, { encoding: 'utf8' });494 }495 }496 assert.ok(fs.existsSync(readmeFile), `File '${readmeFile}' should exist (at least now).`);497 assert.strictEqual(btools.stdout.length, btools.DebugMode ? 14 : 6, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);498 // @ts-ignore499 assert.strictEqual(btools.stdout[0].plain('info'), `Creating/Updating file '${readmeFileName}'.${os.EOL}`, 'stdout first line should contain');500 // @ts-ignore501 assert.strictEqual(btools.stdout[btools.stdout.length - (btools.DebugMode ? 3 : 2)].plain('info'), `Successfully updated readme file '${readmeFile}'.${os.EOL}`, 'stdout line should contain');502 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);503 done();504 });505});506describe(`${thisPackage.name} PostPack() tests`, function () {507 it('should succeed', function (done) {508 var npmTarballEnv = 'NPM_TARBALL';509 if (process.env[npmTarballEnv] !== undefined) {510 delete process.env[npmTarballEnv];511 }512 assert.ok(process.env[npmTarballEnv] === undefined);513 var npmTarballFile = path.resolve('.', npmTarballEnv);514 if (fs.existsSync(npmTarballFile)) {515 fs.removeSync(npmTarballFile);516 }517 assert.ok(!fs.existsSync(npmTarballFile), `File '${npmTarballFile}' should not exist`);518 btools.ConsoleCaptureStart();519 try {520 btools.PostPack([['./lib/clean-package-elements', 'scripts.test']], { logLevel: 'verbose', debug: btools.DebugMode });521 btools.ConsoleCaptureStop();522 } catch (err) {523 btools.ConsoleCaptureStop();524 throw err;525 }526 assert.ok(btools.stdout.length > 0, 'stdout should contain lines');527 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);528 assert.ok((process.env[npmTarballEnv] !== undefined), `Environment variable '${npmTarballEnv}' should exist`);529 assert.ok(fs.existsSync(npmTarballFile), `File '${npmTarballFile}' should exist`);530 assert.strictEqual(fs.readFileSync(npmTarballFile, { encoding: 'utf8' }), process.env[npmTarballEnv], `Environment variable '${npmTarballEnv}' value should equal content of file '${npmTarballFile}'`);531 delete process.env[npmTarballEnv];532 fs.removeSync(npmTarballFile);533 done();534 });535});536describe(`${thisPackage.name} CleanPackage() tests`, function () {537 it('should succeed with temporary package file', function (done) {538 var cleanpackage = require('../lib/clean-package-elements');539 var tempPackageFile = path.resolve('./test/package.json');540 var tempElements = ['scripts.test', 'scripts.prepublish'];541 fs.writeJSONSync(tempPackageFile, thisPackage, { encoding: 'utf8', spaces: 4, EOL: os.EOL });542 btools.ConsoleCaptureStart();543 try {544 cleanpackage.CleanPackageElements('./test', ...tempElements);545 btools.ConsoleCaptureStop();546 } catch (err) {547 btools.ConsoleCaptureStop();548 throw err;549 } finally {550 fs.removeSync(tempPackageFile);551 }552 assert.strictEqual(btools.stdout.length, 4, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);553 // @ts-ignore554 assert.strictEqual(btools.stdout[0].plain('info'), `Cleaning up package file '${tempPackageFile}'.${os.EOL}`, 'stdout first line should contain');555 // @ts-ignore556 assert.strictEqual(btools.stdout[1].plain('info'), `Removing element '${tempElements[0]}'.${os.EOL}`, 'stdout second line should contain');557 // @ts-ignore558 assert.strictEqual(btools.stdout[2].plain('info'), `Element '${tempElements[1]}' doesn't exist.${os.EOL}`, 'stdout third line should contain');559 // @ts-ignore560 assert.strictEqual(btools.stdout[3].plain('info'), `Successfully cleaned up '${tempPackageFile}'.${os.EOL}`, 'stdout fourth line should contain');561 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);562 done();563 });564});565describe(`${thisPackage.name} CreateFallbackReadme() tests`, function () {566 it('should succeed', function (done) {567 var crtfbreadme = require('../lib/create-fallback-readme');568 var tempReadmeFile = path.resolve('./test/README.md');569 if (fs.existsSync(tempReadmeFile)) {570 fs.removeSync(tempReadmeFile);571 }572 btools.ConsoleCaptureStart();573 try {574 crtfbreadme.CreateFallbackReadme('./test');575 btools.ConsoleCaptureStop();576 } catch (err) {577 btools.ConsoleCaptureStop();578 if (fs.existsSync(tempReadmeFile)) {579 fs.removeSync(tempReadmeFile);580 }581 throw err;582 }583 assert.ok(fs.existsSync(tempReadmeFile), `File ${tempReadmeFile} should exist`);584 fs.removeSync(tempReadmeFile);585 assert.ok(!fs.existsSync(tempReadmeFile), `File ${tempReadmeFile} should have been deleted`);586 assert.strictEqual(btools.stdout.length, 2, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);587 // @ts-ignore588 assert.strictEqual(btools.stdout[0].plain('info'), `Creating readme file '${tempReadmeFile}'.${os.EOL}`, 'stdout first line should contain');589 // @ts-ignore590 assert.strictEqual(btools.stdout[1].plain('info'), `Successfully created '${tempReadmeFile}'.${os.EOL}`, 'stdout second line should contain');591 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);592 done();593 });594});595describe(`${thisPackage.name} CheckGlobalDeps() tests`, function () {596 it('should succeed with simple as well as spread syntax', function (done) {597 var checkglobaldeps = require('../lib/check-global-deps');598 btools.ConsoleCaptureStart();599 try {600 checkglobaldeps.CheckGlobalDeps('npm', 'npm');601 checkglobaldeps.CheckGlobalDeps('fakePackage');602 btools.ConsoleCaptureStop();603 } catch (err) {604 btools.ConsoleCaptureStop();605 throw err;606 }607 done();608 });609});610describe(`${thisPackage.name} UpdatePackageVersion() tests`, function () {611 var updatepackage = require('../lib/update-package-version');612 it('should fail with invalid file spec', function (done) {613 btools.ConsoleCaptureStart();614 try {615 // @ts-ignore616 updatepackage.UpdatePackageVersion();617 assert.fail('should have failed');618 } catch (err) {619 btools.ConsoleCaptureStop();620 assert.ok(err instanceof Error, '\'err\' should be an Error object');621 assert.strictEqual(err.message, 'Parameter \'packagePath\' is mandatory.', 'Error message should be');622 }623 done();624 });625 it('should fail with invalid release type', function (done) {626 btools.ConsoleCaptureStart();627 try {628 // @ts-ignore629 updatepackage.UpdatePackageVersion('fakePath');630 assert.fail('should have failed');631 } catch (err) {632 btools.ConsoleCaptureStop();633 assert.ok(err instanceof Error, '\'err\' should be an Error object');634 assert.strictEqual(err.message, 'Parameter \'releaseType\' is mandatory.', 'Error message should be');635 }636 done();637 });638 it('should succeed with temporary package file', function (done) {639 var tempPackageFile = path.resolve('./test/package.json');640 var tempReleaseType = updatepackage.ReleaseType('patch');641 fs.writeJSONSync(tempPackageFile, thisPackage, { encoding: 'utf8', spaces: 4, EOL: os.EOL });642 btools.ConsoleCaptureStart();643 try {644 updatepackage.UpdatePackageVersion('./test', tempReleaseType);645 btools.ConsoleCaptureStop();646 } catch (err) {647 btools.ConsoleCaptureStop();648 throw err;649 } finally {650 fs.removeSync(tempPackageFile);651 }652 assert.strictEqual(btools.stdout.length, 2, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);653 // @ts-ignore654 assert.strictEqual(btools.stdout[0].plain('info'), `Updating version of package file '${tempPackageFile}'.${os.EOL}`, 'stdout first line should contain');655 // @ts-ignore656 assert.strictEqual(btools.stdout[1].plain('info'), `Successfully updated ${tempReleaseType} of version from [${thisPackage.version}] to [${require('semver').inc(thisPackage.version, tempReleaseType)}] in '${tempPackageFile}'.${os.EOL}`, 'stdout second line should contain');657 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);658 done();659 });660});661describe(`${thisPackage.name} TfxIgnore() tests`, function () {662 const tfxutils = require('../lib/tfx-utils');663 it('should fail', (done) => {664 btools.ConsoleCaptureStart();665 try {666 tfxutils.TfxIgnore();667 assert.fail('should have failed');668 } catch (err) {669 btools.ConsoleCaptureStop();670 assert.ok(err instanceof Error, '\'err\' should be an Error object');671 assert.strictEqual(err.message, `VSIX package file '${path.resolve('../vss-extension.json')}' could not be found.`, 'Error message should be');672 }673 done();674 });675 it('should succeed', (done) => {676 var vsixFileIn = './test/vss-extension.json';677 var vsixFileOut = './test/vss-extension.resolved.json';678 if (fs.existsSync(vsixFileIn)) {679 fs.removeSync(vsixFileIn);680 }681 var vsixJson = { files: [{ path: '.' }] };682 fs.writeJSONSync(vsixFileIn, vsixJson, { spaces: 4, encoding: 'utf8', EOL: os.EOL });683 btools.ConsoleCaptureStart();684 try {685 tfxutils.TfxIgnore(vsixFileIn, undefined, { logLevel: 'debug' });686 btools.ConsoleCaptureStop();687 } catch (err) {688 btools.ConsoleCaptureStop();689 throw err;690 }691 assert.ok(fs.existsSync(vsixFileOut), `File '${vsixFileOut}' should exist`);692 fs.removeSync(vsixFileOut);693 assert.ok(fs.existsSync(vsixFileIn), `File '${vsixFileIn}' should (still) exist`);694 fs.removeSync(vsixFileIn);695 assert.ok(btools.stdout.length >= 2, `stdout should contain two or more lines:${os.EOL}${btools.stdout.join('')}`);696 // @ts-ignore697 assert.strictEqual(btools.stdout[0].plain('info'), `Processing VSIX package file '${path.resolve(vsixFileIn)}'.${os.EOL}`, 'stdout first line should contain');698 // @ts-ignore699 assert.strictEqual(btools.stdout[btools.stdout.length - 1].plain('info'), `Successfully updated VSIX package file '${path.resolve(vsixFileOut)}'.${os.EOL}`, 'stdout second line should contain');700 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);701 done();702 });703});704describe(`${thisPackage.name} TfxMkboot() tests`, function () {705 const tfxutils = require('../lib/tfx-utils');706 it('should fail', (done) => {707 btools.ConsoleCaptureStart();708 try {709 tfxutils.TfxMkboot2();710 assert.fail('should have failed');711 } catch (err) {712 btools.ConsoleCaptureStop();713 assert.ok(err instanceof Error, '\'err\' should be an Error object');714 assert.strictEqual(err.message, `Task file '${path.resolve('./task.json')}' could not be found.`, 'Error message should be');715 }716 done();717 });718 it('should succeed', (done) => {719 var tempPath = fs.mkdtempSync(path.join(os.tmpdir(), '_temp_npmbuildtools-'));720 var extensionJsonFile = path.resolve(tempPath, 'vss-extension.json');721 var packagePath = path.resolve(tempPath, 'test'); fs.ensureDirSync(packagePath);722 var packageJsonFile = path.resolve(packagePath, 'package.json');723 var taskJsonFile = path.resolve(packagePath, 'task.json');724 var bootFile = path.resolve(packagePath, 'boot.js');725 var tempPackageName = 'Test Package';726 var extensionJson = {727 publisher: 'testpublisher',728 id: 'test-extension-id',729 version: '0.0.1'730 };731 fs.writeJSONSync(extensionJsonFile, extensionJson, { spaces: 4, encoding: 'utf8', EOL: os.EOL });732 var PckgJson = {733 main: 'index.js',734 version: '4.5.6'735 };736 fs.writeJSONSync(packageJsonFile, PckgJson, { spaces: 4, encoding: 'utf8', EOL: os.EOL });737 var taskJson = {738 id: 'Test-Package-Id',739 name: tempPackageName,740 version: {741 Major: 1,742 Minor: 2,743 Patch: 3744 },745 execution: {746 Node10: {747 target: 0748 }749 }750 };751 fs.writeJSONSync(taskJsonFile, taskJson, { spaces: 4, encoding: 'utf8', EOL: os.EOL });752 btools.ConsoleCaptureStart();753 try {754 tfxutils.TfxMkboot2({ packagePath: packagePath, incrementReleaseType: 'minor', consoleOptions: { logLevel: 'debug' } }, 'command1', 'command2');755 btools.ConsoleCaptureStop();756 } catch (err) {757 btools.ConsoleCaptureStop();758 throw err;759 }760 assert.ok(fs.existsSync(bootFile), `File '${bootFile}' should exist`);761 assert.ok(fs.existsSync(extensionJsonFile), `File '${extensionJsonFile}' should (still) exist`);762 assert.ok(fs.existsSync(packageJsonFile), `File '${packageJsonFile}' should (still) exist`);763 assert.ok(fs.existsSync(taskJsonFile), `File '${taskJsonFile}' should (still) exist`);764 PckgJson.version = semver.inc(PckgJson.version, 'patch');765 fs.writeJSONSync(packageJsonFile, PckgJson, { spaces: 4, encoding: 'utf8', EOL: os.EOL });766 btools.ConsoleCaptureStart();767 try {768 tfxutils.TfxMkboot2({ packagePath: packagePath, incrementReleaseType: 'minor', consoleOptions: { logLevel: 'debug' } }, 'command1', 'command2');769 btools.ConsoleCaptureStop();770 } catch (err) {771 btools.ConsoleCaptureStop();772 throw err;773 }774 assert.ok(fs.existsSync(bootFile), `File '${bootFile}' should (still) exist`);775 assert.ok(fs.existsSync(extensionJsonFile), `File '${extensionJsonFile}' should (still) exist`);776 assert.ok(fs.existsSync(packageJsonFile), `File '${packageJsonFile}' should (still) exist`);777 assert.ok(fs.existsSync(taskJsonFile), `File '${taskJsonFile}' should (still) exist`);778 fs.removeSync(tempPath);779 assert.ok(btools.stdout.length >= 2, `stdout should contain two or more lines:${os.EOL}${btools.stdout.join('')}`);780 // @ts-ignore781 assert.strictEqual(btools.stdout[0].plain('info'), `Processing package in '${packagePath}'.${os.EOL}`, 'stdout first line should contain');782 // @ts-ignore783 assert.strictEqual(btools.stdout[btools.stdout.length - 1].plain('info'), `Finished processing package '${tempPackageName}' in '${packagePath}'.${os.EOL}`, 'stdout second line should contain');784 assert.strictEqual(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);785 done();786 });787});788describe(`${thisPackage.name} Readme should be up to date`, function () {789 it('CheckReadme() should succeed', function (done) {790 var packagePath = path.resolve('.');791 var readmeFileName = 'README.adoc';792 var result;793 btools.ConsoleCaptureStart();794 try {795 result = btools.CheckReadme(packagePath, readmeFileName, { updateTimestamp: true });796 btools.ConsoleCaptureStop();797 } catch (err) {798 btools.ConsoleCaptureStop();799 throw err;800 }801 if (result) {802 assert.fail(`Readme file '${path.join(packagePath, readmeFileName)}' needs to be updated:${os.EOL}${result}`);803 }804 done();805 });...

Full Screen

Full Screen

_suite.ts

Source:_suite.ts Github

copy

Full Screen

1import * as os from 'os';2import * as fs from 'fs-extra';3import * as path from 'path';4import * as assert from 'assert';5import * as tsjson from '../index';6import btools from '@nbb.com/npmbuildtools';7const thisPackage = require('../package.json');8if (btools.TerminalCanBlock) {9 console.log('\u001b[2J'); // clear screen10}11if (!fs.existsSync(`${__filename}.map`)) {12 console.error(`There is no source map for this suite, so you won't be able to debug it! To change this, turn on the 'sourceMap' typescript compiler option in your 'tsconfig.json' file.`);13}14console.log('Running Mocha Test Suite ...');15describe(`${thisPackage.name} Load() tests`, function () {16 var jsonFile: string = path.join(os.tmpdir(), 'TestSettings.json');17 class TestClass1 {18 StringValue: string = '';19 }20 class TestClass2 {21 StringValue: string = '';22 NumberValue: number = 0;23 }24 before( function() {25 });26 after(() => {27 });28 it('should fail without creating a file due to empty object', function(done: MochaDone) {29 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }30 var target: object | undefined = undefined;31 btools.ConsoleCaptureStart();32 try {33 target = tsjson.Load(jsonFile, new Object());34 assert.fail('should have failed');35 } catch (error) {36 btools.ConsoleCaptureStop();37 assert.equal((<Error>error).message, `Object cannot be loaded because it doesn't contain any properties.`, `error message should contain`);38 }39 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);40 assert.equal(target, undefined, `target should still be undefined`);41 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);42 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);43 done();44 });45 46 it('should fail without creating a file due to invalid JSON file', function(done: MochaDone) {47 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }48 // Create invalid file49 fs.writeFileSync(jsonFile, `{ "invalidJSON": }`);50 var target: TestClass1 | undefined = undefined;51 btools.ConsoleCaptureStart();52 try {53 target = tsjson.Load(jsonFile, new TestClass1());54 btools.ConsoleCaptureStop();55 assert.fail('should have failed');56 } catch (error) {57 btools.ConsoleCaptureStop();58 assert.equal((<Error>error).message, `${jsonFile}: Unexpected token } in JSON at position 17`, `error message should contain`);59 }60 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should still exist`);61 assert.equal(target, undefined, `target should still be undefined`);62 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);63 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);64 done();65 });66 67 it('should succeed without creating a file', function(done: MochaDone) {68 //this.timeout(10000);69 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }70 var target: TestClass1 | undefined = undefined;71 btools.ConsoleCaptureStart();72 try {73 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: false, consoleOptions: { logLevel: 'debug' } });74 btools.ConsoleCaptureStop();75 } catch (error) {76 btools.ConsoleCaptureStop();77 assert.fail(`should not have failed with error [${<Error>error.message}]`);78 }79 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);80 assert.notEqual(target, undefined, `target should not be undefined`);81 assert.equal(target.StringValue, '', `target's StringValue property should still be an empty string`);82 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);83 assert.equal(btools.stderr.length, 2, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);84 // @ts-ignore85 assert.equal(btools.stderr[0].plain('error'), `Settings file '${jsonFile}' could not be found.${os.EOL}`, `stderr first line should contain`);86 // @ts-ignore87 assert.equal(btools.stderr[1].plain('error'), `Object contains only default values.${os.EOL}`, `stderr second line should contain`);88 done();89 });90 91 it('should fail without creating a file', function(done: MochaDone) {92 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }93 var target: TestClass1 | undefined = undefined;94 btools.ConsoleCaptureStart();95 try {96 target = tsjson.Load(jsonFile, new TestClass1());97 btools.ConsoleCaptureStop();98 assert.fail('should have failed');99 } catch (error) {100 btools.ConsoleCaptureStop();101 assert.equal((<Error>error).message, `Settings file '${jsonFile}' could not be found.`, `error message should contain`);102 }103 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);104 assert.equal(target, undefined, `target should still be undefined`);105 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);106 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);107 done();108 });109 110 it('should fail without creating a file with supplied error text', function(done: MochaDone) {111 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }112 var target: TestClass1 | undefined = undefined;113 var errTxt: string = `File missing.`;114 btools.ConsoleCaptureStart();115 try {116 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: errTxt });117 btools.ConsoleCaptureStop();118 assert.fail('should have failed');119 } catch (error) {120 btools.ConsoleCaptureStop();121 assert.equal((<Error>error).message, errTxt, `error message should contain`);122 }123 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);124 assert.equal(target, undefined, `target should still be undefined`);125 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);126 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);127 done();128 });129 130 it('should fail without creating a file with supplied error object', function(done: MochaDone) {131 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }132 var target: TestClass1 | undefined = undefined;133 var errObj: Error = Error(`File missing.`);134 btools.ConsoleCaptureStart();135 try {136 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: errObj });137 btools.ConsoleCaptureStop();138 assert.fail('should have failed');139 } catch (error) {140 btools.ConsoleCaptureStop();141 assert.equal((<Error>error).message, errObj.message, `error message should contain`);142 }143 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);144 assert.equal(target, undefined, `target should still be undefined`);145 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);146 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);147 done();148 });149 150 it('should fail without creating a file due to object being default', function(done: MochaDone) {151 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }152 var target: TestClass1 | undefined = undefined;153 btools.ConsoleCaptureStart();154 try {155 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: false, failOnObjectIsDefault: true });156 btools.ConsoleCaptureStop();157 assert.fail('should have failed');158 } catch (error) {159 btools.ConsoleCaptureStop();160 assert.equal((<Error>error).message, 'Object contains only default values.', `error message should contain`);161 }162 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);163 assert.equal(target, undefined, `target should still be undefined`);164 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);165 assert.equal(btools.stderr.length, 1, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);166 // @ts-ignore167 assert.equal(btools.stderr[0].plain('error'), `Settings file '${jsonFile}' could not be found.${os.EOL}`, `stderr first line should contain`);168 done();169 });170 171 it('should fail without creating a file due to object being default with supplied error text', function(done: MochaDone) {172 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }173 var target: TestClass1 | undefined = undefined;174 var errTxt: string = `Object is default.`;175 btools.ConsoleCaptureStart();176 try {177 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: false, failOnObjectIsDefault: errTxt });178 btools.ConsoleCaptureStop();179 assert.fail('should have failed');180 } catch (error) {181 btools.ConsoleCaptureStop();182 assert.equal((<Error>error).message, errTxt, `error message should contain`);183 }184 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);185 assert.equal(target, undefined, `target should still be undefined`);186 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);187 assert.equal(btools.stderr.length, 1, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);188 // @ts-ignore189 assert.equal(btools.stderr[0].plain('error'), `Settings file '${jsonFile}' could not be found.${os.EOL}`, `stderr first line should contain`);190 done();191 });192 193 it('should fail without creating a file due to object being default with supplied error object', function(done: MochaDone) {194 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }195 var target: TestClass1 | undefined = undefined;196 var errObj: Error = Error(`Object is default.`);197 btools.ConsoleCaptureStart();198 try {199 target = tsjson.Load(jsonFile, new TestClass1(), { failOnFileNotFound: false, failOnObjectIsDefault: errObj });200 btools.ConsoleCaptureStop();201 assert.fail('should have failed');202 } catch (error) {203 btools.ConsoleCaptureStop();204 assert.equal((<Error>error).message, errObj.message, `error message should contain`);205 }206 assert.equal(fs.existsSync(jsonFile), false, `File '${jsonFile}' should not exist`);207 assert.equal(target, undefined, `target should still be undefined`);208 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);209 assert.equal(btools.stderr.length, 1, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);210 // @ts-ignore211 assert.equal(btools.stderr[0].plain('error'), `Settings file '${jsonFile}' could not be found.${os.EOL}`, `stderr first line should contain`);212 done();213 });214 215 it('should fail having created a file but due to object being default', function(done: MochaDone) {216 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }217 var target: TestClass1 | undefined = undefined;218 btools.ConsoleCaptureStart();219 try {220 target = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnObjectIsDefault: true });221 btools.ConsoleCaptureStop();222 assert.fail('should have failed');223 } catch (error) {224 btools.ConsoleCaptureStop();225 assert.equal((<Error>error).message, `Settings file '${jsonFile}' didn't exist, but a scaffolding has been created.`, `error message should contain`);226 }227 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);228 assert.equal(target, undefined, `target should still be undefined`);229 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);230 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);231 done();232 });233 234 it('should succeed having created a file', function(done: MochaDone) {235 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }236 var target: TestClass1 | undefined = undefined;237 btools.ConsoleCaptureStart();238 try {239 target = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });240 btools.ConsoleCaptureStop();241 } catch (error) {242 btools.ConsoleCaptureStop();243 assert.fail(`should not have failed with error [${<Error>error.message}]`);244 }245 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);246 assert.notEqual(target, undefined, `target should not be undefined`);247 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);248 assert.equal(btools.stderr.length, 2, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);249 // @ts-ignore250 assert.equal(btools.stderr[0].plain('error'), `Settings file '${jsonFile}' didn't exist, but a scaffolding has been created.${os.EOL}`, `stderr first line should contain`);251 // @ts-ignore252 assert.equal(btools.stderr[1].plain('error'), `Object contains only default values.${os.EOL}`, `stderr second line should contain`);253 done();254 });255 256 it('should succeed having found a file emitting verbose output', function(done: MochaDone) {257 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }258 259 // Create a default file260 btools.ConsoleCaptureStart();261 tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });262 btools.ConsoleCaptureStop();263 var target: TestClass1 | undefined = undefined;264 btools.ConsoleCaptureStart();265 try {266 target = tsjson.Load(jsonFile, new TestClass1(), { consoleOptions: { logLevel: 'debug' } });267 btools.ConsoleCaptureStop();268 } catch (error) {269 btools.ConsoleCaptureStop();270 assert.fail(`should not have failed with error [${<Error>error.message}]`);271 }272 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);273 assert.notEqual(target, undefined, `target should not be undefined`);274 assert.equal(btools.stdout.length, btools.DebugMode ? 2 : 1, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);275 if (btools.DebugMode) {276 // @ts-ignore277 assert.equal(btools.stdout[0].plain('debug'), `Value '' of Property 'StringValue' in object remains unchanged due to value '' from file '${jsonFile}' being equal.${os.EOL}`, `stdout first line should contain`);278 }279 // @ts-ignore280 assert.equal(btools.stdout[btools.DebugMode ? 1 : 0].plain('info'), `File '${jsonFile}' won't be updated.${os.EOL}`, `stdout second line should contain`);281 assert.equal(btools.stderr.length, 1, `stderr should contain exact number of lines:${os.EOL}${btools.stderr.join('')}`);282 // @ts-ignore283 assert.equal(btools.stderr[0].plain('error'), `Object contains only default values.${os.EOL}`, `stderr first line should contain`);284 done();285 });286 287 it('should fail having found a file but due to object being default', function(done: MochaDone) {288 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }289 290 // Create a default file291 btools.ConsoleCaptureStart();292 tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });293 btools.ConsoleCaptureStop();294 var target: TestClass1 | undefined = undefined;295 btools.ConsoleCaptureStart();296 try {297 target = tsjson.Load(jsonFile, new TestClass1(), { failOnObjectIsDefault: true });298 btools.ConsoleCaptureStop();299 assert.fail('should have failed');300 } catch (error) {301 btools.ConsoleCaptureStop();302 assert.equal((<Error>error).message, `Object contains only default values.`, `error message should contain`);303 }304 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);305 assert.equal(target, undefined, `target should still be undefined`);306 assert.equal(btools.stdout.length, 0, `stdout shouldn't contain any lines:${os.EOL}${btools.stdout.join('')}`);307 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);308 done();309 });310 311 it('should succeed having found a file with 1 non-default value', function(done: MochaDone) {312 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }313 314 // Create a default file315 btools.ConsoleCaptureStart();316 var targetDefault = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });317 btools.ConsoleCaptureStop();318 // Apply change to file319 targetDefault.StringValue = `non-default`;320 fs.writeJSONSync(jsonFile, targetDefault);321 var target: TestClass1 | undefined = undefined;322 btools.ConsoleCaptureStart();323 try {324 target = tsjson.Load(jsonFile, new TestClass1(), { consoleOptions: { logLevel: 'debug' } });325 btools.ConsoleCaptureStop();326 } catch (error) {327 btools.ConsoleCaptureStop();328 assert.fail(`should not have failed with error [${<Error>error.message}]`);329 }330 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);331 assert.notEqual(target, undefined, `target should not be undefined`);332 assert.equal(btools.stdout.length, btools.DebugMode ? 2 : 1, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);333 if (btools.DebugMode) {334 // @ts-ignore335 assert.equal(btools.stdout[0].plain('debug'), `Value of Property 'StringValue' is set from '' to '${target.StringValue}'.${os.EOL}`, `stdout first line should contain`);336 }337 // @ts-ignore338 assert.equal(btools.stdout[btools.DebugMode ? 1 : 0].plain('info'), `File '${jsonFile}' won't be updated.${os.EOL}`, `stdout second line should contain`);339 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);340 done();341 });342 343 it('should succeed having found a file with 1 unknown value', function(done: MochaDone) {344 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }345 346 // Create a default file with different class TestClass2347 btools.ConsoleCaptureStart();348 var targetDefault = tsjson.Load(jsonFile, new TestClass2(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });349 btools.ConsoleCaptureStop();350 // Apply change to file351 targetDefault.StringValue = 'non-default';352 fs.writeJSONSync(jsonFile, targetDefault);353 var target: TestClass1 | undefined = undefined;354 btools.ConsoleCaptureStart();355 try {356 target = tsjson.Load(jsonFile, new TestClass1(), { consoleOptions: { logLevel: 'debug' } });357 btools.ConsoleCaptureStop();358 } catch (error) {359 btools.ConsoleCaptureStop();360 assert.fail(`should not have failed with error [${<Error>error.message}]`);361 }362 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);363 assert.notEqual(target, undefined, `target should not be undefined`);364 assert.equal(btools.stdout.length, btools.DebugMode ? 3 : 1, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);365 if (btools.DebugMode) {366 // @ts-ignore367 assert.equal(btools.stdout[0].plain('debug'), `Value of Property 'StringValue' is set from '' to '${target.StringValue}'.${os.EOL}`, `stdout first line should contain`);368 // @ts-ignore369 assert.equal(btools.stdout[1].plain('debug'), `Property 'NumberValue' wasn't found in object and will be skipped.${os.EOL}`, `stdout second line should contain`);370 }371 // @ts-ignore372 assert.equal(btools.stdout[btools.DebugMode ? 2 : 0].plain('info'), `File '${jsonFile}' won't be updated.${os.EOL}`, `stdout third line should contain`);373 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);374 done();375 });376 377 it('should succeed having found a file with 1 missing value', function(done: MochaDone) {378 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }379 380 // Create a default file with different class TestClass1381 btools.ConsoleCaptureStart();382 var targetDefault = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });383 btools.ConsoleCaptureStop();384 // Apply change to file385 targetDefault.StringValue = 'non-default';386 fs.writeJSONSync(jsonFile, targetDefault);387 var target: TestClass1 | undefined = undefined;388 btools.ConsoleCaptureStart();389 try {390 target = tsjson.Load(jsonFile, new TestClass2(), { consoleOptions: { logLevel: 'debug' } });391 btools.ConsoleCaptureStop();392 } catch (error) {393 btools.ConsoleCaptureStop();394 assert.fail(`should not have failed with error [${<Error>error.message}]`);395 }396 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);397 assert.notEqual(target, undefined, `target should not be undefined`);398 assert.equal(btools.stdout.length, btools.DebugMode ? 3 : 1, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);399 if (btools.DebugMode) {400 // @ts-ignore401 assert.equal(btools.stdout[0].plain('debug'), `Value of Property 'StringValue' is set from '' to '${target.StringValue}'.${os.EOL}`, `stdout first line should contain`);402 // @ts-ignore403 assert.equal(btools.stdout[1].plain('debug'), `Value for property 'NumberValue' wasn't found in file '${jsonFile}'.${os.EOL}`, `stdout second line should contain`);404 }405 // @ts-ignore406 assert.equal(btools.stdout[btools.DebugMode ? 2 : 0].plain('info'), `Values are missing in file '${jsonFile}', but flag WriteOnLoad.Update has not been set in options.writeOnLoad.${os.EOL}`, `stderr first line should contain`);407 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);408 done();409 });410 411 it('should succeed having found a file with 1 unknown value having WriteOnLoad.Update set', function(done: MochaDone) {412 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }413 414 // Create a default file with different class TestClass2415 btools.ConsoleCaptureStart();416 var targetDefault = tsjson.Load(jsonFile, new TestClass2(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });417 btools.ConsoleCaptureStop();418 // Apply change to file419 targetDefault.StringValue = 'non-default';420 fs.writeJSONSync(jsonFile, targetDefault);421 var target: TestClass1 | undefined = undefined;422 btools.ConsoleCaptureStart();423 try {424 target = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Update, consoleOptions: { logLevel: 'debug' } });425 btools.ConsoleCaptureStop();426 } catch (error) {427 btools.ConsoleCaptureStop();428 assert.fail(`should not have failed with error [${<Error>error.message}]`);429 }430 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);431 assert.notEqual(target, undefined, `target should not be undefined`);432 assert.equal(btools.stdout.length, btools.DebugMode ? 3 : 0, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);433 if (btools.DebugMode) {434 // @ts-ignore435 assert.equal(btools.stdout[0].plain('debug'), `Value of Property 'StringValue' is set from '' to '${target.StringValue}'.${os.EOL}`, `stdout first line should contain`);436 // @ts-ignore437 assert.equal(btools.stdout[1].plain('debug'), `Property 'NumberValue' wasn't found in object and will be skipped.${os.EOL}`, `stdout second line should contain`);438 // @ts-ignore439 assert.equal(btools.stdout[2].plain('debug'), `File '${jsonFile}' doesn't need to be updated.${os.EOL}`, `stdout third line should contain`);440 }441 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);442 done();443 });444 445 it('should succeed having found a file with 1 missing value having WriteOnLoad.Update set', function(done: MochaDone) {446 if (fs.existsSync(jsonFile)) { fs.removeSync(jsonFile); }447 448 // Create a default file with different class TestClass1449 btools.ConsoleCaptureStart();450 var targetDefault = tsjson.Load(jsonFile, new TestClass1(), { writeOnLoad: tsjson.WriteOnLoad.Create, failOnFileNotFound: false });451 btools.ConsoleCaptureStop();452 // Apply change to file453 targetDefault.StringValue = 'non-default';454 fs.writeJSONSync(jsonFile, targetDefault);455 var target: TestClass1 | undefined = undefined;456 btools.ConsoleCaptureStart();457 try {458 target = tsjson.Load(jsonFile, new TestClass2(), { writeOnLoad: tsjson.WriteOnLoad.Update, consoleOptions: { logLevel: 'debug' } });459 btools.ConsoleCaptureStop();460 } catch (error) {461 btools.ConsoleCaptureStop();462 assert.fail(`should not have failed with error [${<Error>error.message}]`);463 }464 assert.equal(fs.existsSync(jsonFile), true, `File '${jsonFile}' should exist`);465 assert.notEqual(target, undefined, `target should not be undefined`);466 assert.equal(btools.stdout.length, btools.DebugMode ? 3 : 1, `stdout should contain exact number of lines:${os.EOL}${btools.stdout.join('')}`);467 if (btools.DebugMode) {468 // @ts-ignore469 assert.equal(btools.stdout[0].plain('debug'), `Value of Property 'StringValue' is set from '' to '${target.StringValue}'.${os.EOL}`, `stdout first line should contain`);470 // @ts-ignore471 assert.equal(btools.stdout[1].plain('debug'), `Value for property 'NumberValue' wasn't found in file '${jsonFile}'.${os.EOL}`, `stdout second line should contain`);472 }473 // @ts-ignore474 assert.equal(btools.stdout[btools.DebugMode ? 2 : 0].plain('info'), `Updating file '${jsonFile}' due to missing values.${os.EOL}`, `stdout third line should contain`);475 assert.equal(btools.stderr.length, 0, `stderr shouldn't contain any lines:${os.EOL}${btools.stderr.join('')}`);476 done();477 });478 479});480describe(`${thisPackage.name} Readme should be up to date`, function() {481 it('CheckReadme() should succeed', function(done) {482 var packagePath = path.resolve('.');483 var readmeFileName = 'README.adoc';484 var result;485 btools.ConsoleCaptureStart();486 try {487 result = btools.CheckReadme(packagePath, readmeFileName, { updateTimestamp: true });488 btools.ConsoleCaptureStop();489 } catch(err) {490 btools.ConsoleCaptureStop();491 throw err;492 }493 if (result) {494 assert.fail(`Readme file '${path.join(packagePath, readmeFileName)}' needs to be updated:${os.EOL}${result}`);495 }496 done();497 });...

Full Screen

Full Screen

FMouseConsole.js

Source:FMouseConsole.js Github

copy

Full Screen

1//==========================================================2// <T>鼠标对象控制台。</T>3//4// @console5// @author maocy6// @version 1502037//==========================================================8MO.FMouseConsole = function FMouseConsole(o){9 o = MO.Class.inherits(this, o, MO.FConsole);10 //..........................................................11 // @attribute12 o._scopeCd = MO.EScope.Local;13 // @attribute14 o._activeCapture = null;15 //o._captures = null;16 //..........................................................17 // @event18 o.onMouseDown = MO.FMouseConsole_onMouseDown;19 o.onMouseMove = MO.FMouseConsole_onMouseMove;20 o.onMouseUp = MO.FMouseConsole_onMouseUp;21 //..........................................................22 // @method23 o.construct = MO.FMouseConsole_construct;24 // method25 o.captureStart = MO.FMouseConsole_captureStart;26 o.capture = MO.FMouseConsole_capture;27 o.captureStop = MO.FMouseConsole_captureStop;28 // method29 o.register = MO.FMouseConsole_register;30 o.unregister = MO.FMouseConsole_unregister;31 o.clear = MO.FMouseConsole_clear;32 // method33 return o;34}35//==========================================================36// <T>鼠标按下处理。</T>37//38// @method39// @param p:event:htmlEvent 事件40//==========================================================41MO.FMouseConsole_onMouseDown = function FMouseConsole_onMouseDown(p){42 var o = this;43 // 检查来源44 var s = MO.RHtml.searchLinker(p.hSource, MO.MMouseCapture);45 if(!s){46 return;47 }48 // 检查测试49 if(!s.testMouseCapture()){50 return;51 }52 // 捕捉开始处理53 o._activeCapture = s;54 o.captureStart(p);55}56//==========================================================57// <T>鼠标移动处理。</T>58//59// @method60// @param p:event:htmlEvent 事件61//==========================================================62MO.FMouseConsole_onMouseMove = function FMouseConsole_onMouseMove(p){63 var o = this;64 // 检查拖拽处理65 if(!o._activeCapture){66 return;67 }68 // 拖拽处理69 o.capture(p);70}71//==========================================================72// <T>鼠标抬起处理。</T>73//74// @method75// @param p:event:htmlEvent 事件76//==========================================================77MO.FMouseConsole_onMouseUp = function FMouseConsole_onMouseUp(p){78 var o = this;79 // 检查拖拽处理80 if(!o._activeCapture){81 return;82 }83 // 捕捉结束处理84 o.captureStop(p);85}86//==========================================================87// <T>构造处理。</T>88//89// @method90//==========================================================91MO.FMouseConsole_construct = function FMouseConsole_construct(){92 var o = this;93 o.__base.FConsole.construct.call(o);94 // 创建属性95 //o._captures = new TObjects();96 // 注册事件97 MO.RWindow.lsnsMouseDown.register(o, o.onMouseDown);98 MO.RWindow.lsnsMouseMove.register(o, o.onMouseMove);99 MO.RWindow.lsnsMouseUp.register(o, o.onMouseUp);100}101//==========================================================102// <T>捕捉开始处理。</T>103//104// @method105// @param p:event:htmlEvent 事件106//==========================================================107MO.FMouseConsole_captureStart = function FMouseConsole_captureStart(p){108 var o = this;109 var c = o._activeCapture;110 if(c){111 MO.RWindow.setOptionSelect(false);112 c.onMouseCaptureStart(p);113 }114}115//==========================================================116// <T>捕捉处理。</T>117//118// @method119// @param p:event:htmlEvent 事件120//==========================================================121MO.FMouseConsole_capture = function FMouseConsole_capture(p){122 var o = this;123 var c = o._activeCapture;124 if(c){125 if(c.testMouseCapture()){126 c.onMouseCapture(p);127 }else{128 o.captureStop(p)129 }130 }131}132//==========================================================133// <T>捕捉结束处理。</T>134//135// @method136// @param p:event:htmlEvent 事件137//==========================================================138MO.FMouseConsole_captureStop = function FMouseConsole_captureStop(p){139 var o = this;140 var c = o._activeCapture;141 if(c){142 c.onMouseCaptureStop(p);143 o._activeCapture = null;144 }145 MO.RWindow.setOptionSelect(true);146}147//==========================================================148// <T>注册一个鼠标捕捉对象。</T>149//150// @method151// @param p:capture:MMouseCapture 鼠标捕捉152//==========================================================153MO.FMouseConsole_register = function FMouseConsole_register(p){154 //this._captures.push(p);155}156//==========================================================157// <T>注销一个鼠标捕捉对象。</T>158//159// @method160// @param p:capture:MMouseCapture 鼠标捕捉161//==========================================================162MO.FMouseConsole_unregister = function FMouseConsole_unregister(p){163 //this._captures.remove(p);164}165//==========================================================166// <T>清空处理。</T>167//168// @method169//==========================================================170MO.FMouseConsole_clear = function FMouseConsole_clear(){171 //this._captures.clear();...

Full Screen

Full Screen

ScannerComponent.js

Source:ScannerComponent.js Github

copy

Full Screen

1import React from "react";2import { Button, Select, MenuItem } from "@material-ui/core";3import {4 BrowserMultiFormatReader,5 BarcodeFormat,6 DecodeHintType,7 NotFoundException8} from "@zxing/library";9export default function ScannerComponent(props) {10 const [loading, setLoading] = React.useState(props.loading || false);11 const [showButtons, setShowButtons] = React.useState(12 props.showButtons === true ? true : false13 );14 const [isRunning, setIsRunning] = React.useState(false);15 const [source, setSource] = React.useState("");16 const [devices, setDevices] = React.useState([]);17 const [scanResult, setScanResult] = React.useState("");18 const [codeReader, setCodeReader] = React.useState(19 new BrowserMultiFormatReader()20 );21 const [formats, setFormats] = React.useState([22 BarcodeFormat.QR_CODE,23 BarcodeFormat.DATA_MATRIX,24 BarcodeFormat.CODE_39,25 BarcodeFormat.CODE_12826 ]);27 const [hints, setHints] = React.useState(new Map());28 React.useEffect(() => {29 hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);30 // codeReader.getVideoInputDevices().then(videoInputDevices => {31 // setSource(videoInputDevices[0].deviceId);32 // if (videoInputDevices.length >= 1) {33 // videoInputDevices.forEach(element => {34 // setDevices([...devices, element]);35 // });36 // }37 // });38 }, []);39 React.useEffect(() => {40 setLoading(props.loading);41 setShowButtons(props.showButtons);42 }, [props.loading, props.showButtons]);43 React.useEffect(() => {44 if (props.started === true) {45 if (isRunning === false) {46 captureStart(props.onResult);47 }48 } else if (props.started === false) {49 if (isRunning === true) {50 captureStop();51 }52 } else {53 }54 }, [props.started]);55 const captureStart = (callback = () => {}, stopOnCapture = true) => {56 setIsRunning(true);57 codeReader.decodeFromVideoDevice(source, "video", (result, err) => {58 if (result) {59 setScanResult(result);60 if (stopOnCapture === true) {61 captureStop();62 }63 callback(result, err);64 }65 if (err && !(err instanceof NotFoundException)) {66 console.log("error", err);67 }68 });69 };70 const captureStop = () => {71 setIsRunning(false);72 codeReader.reset();73 };74 return (75 <div>76 {showButtons && (77 <div>78 <Button79 color="primary"80 variant="contained"81 onClick={() => captureStart(props.onResult)}82 >83 Scan Barcode84 </Button>{" "}85 <Button color="primary" variant="contained" onClick={captureStop}>86 Stop Scanner87 </Button>88 </div>89 )}90 <div>91 <video92 id="video"93 width="100%"94 height="100%"95 style={{ border: "1px solid gray" }}96 ></video>97 </div>98 <Select value={source} onChange={event => setSource(event.target.value)}>99 {devices.map((device, index) => {100 return (101 <MenuItem key={index} value={device.deviceId}>102 {device.label}103 </MenuItem>104 );105 })}106 </Select>107 </div>108 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2(async () => {3 const browser = await qawolf.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click("input[name=q]");7 await page.fill("input[name=q]", "QA Wolf");8 await page.press("input[name=q]", "Enter");9 await page.click("text=QA Wolf: Create browser tests in minutes");10 await qawolf.stopVideos();11 await browser.close();12})();13const qawolf = require("qawolf");14(async () => {15 const browser = await qawolf.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.click("input[name=q]");19 await page.fill("input[name=q]", "QA Wolf");20 await page.press("input[name=q]", "Enter");21 await page.click("text=QA Wolf: Create browser tests in minutes");22 await qawolf.stopVideos();23 await browser.close();24})();25const qawolf = require("qawolf");26(async () => {27 const browser = await qawolf.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.click("input[name=q]");31 await page.fill("input[name=q]", "QA Wolf");32 await page.press("input[name=q]", "Enter");33 await page.click("text=QA Wolf: Create browser tests in minutes");34 await qawolf.stopVideos();35 await browser.close();36})();37const qawolf = require("qawolf");38(async () => {39 const browser = await qawolf.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.click("input[name=q]");43 await page.fill("input[name=q]", "QA Wolf");44 await page.press("input[name=q]", "Enter");

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const { firefox } = require("playwright");3(async () => {4 const browser = await firefox.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await qawolf.create("test", { page });8 await qawolf.stop();9 await browser.close();10})();11const qawolf = require("qawolf");12const { firefox } = require("playwright");13(async () => {14 const browser = await firefox.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await qawolf.create("test", { page });18 await qawolf.stop();19 await browser.close();20})();21const qawolf = require("qawolf");22const { firefox } = require("playwright");23(async () => {24 const browser = await firefox.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 await qawolf.create("test", { page });28 await qawolf.stop();29 await browser.close();30})();31const qawolf = require("qawolf");32const { firefox } = require("playwright");33(async () => {34 const browser = await firefox.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 await qawolf.create("test", { page });38 await qawolf.stop();39 await browser.close();40})();41const qawolf = require("qawolf");42const { firefox } = require("playwright");43(async () => {44 const browser = await firefox.launch();45 const context = await browser.newContext();46 const page = await context.newPage();47 await qawolf.create("test", { page });48 await qawolf.stop();49 await browser.close();50})();51const qawolf = require("qawolf");52const { firefox } = require("playwright");53(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require('qawolf');2const { firefox } = require('playwright');3(async () => {4 const browser = await launch(firefox);5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.goto('http:/

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch } = require("qawolf");2const browser = await launch();3const context = await browser.newContext();4const page = await context.newPage();5await page.click("input[name='q']");6await page.fill("input[name='q']", "Hello World!");7await page.press("input[name='q']", "Enter");8await page.screenshot({ path: `test.png` });9await browser.close();10await capture.stop();11const { launch } = require("qawolf");12const { test, expect } = require("@playwright/test");13test("test", async () => {14 const browser = await launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await page.click("input[name='q']");18 await page.fill("input[name='q']", "Hello World!");19 await page.press("input[name='q']", "Enter");20 await page.screenshot({ path: `test.png` });21 await browser.close();22 await capture.stop();23});24import { launch } from "qawolf";25import { test, expect } from "@playwright/test";26test("test", async () => {27 const browser = await launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.click("input[name='q']");31 await page.fill("input[name='q']", "Hello World!");32 await page.press("input[name='q']", "Enter");33 await page.screenshot({ path: `test.png` });34 await browser.close();35 await capture.stop();36});37import { launch } from "qawolf";38const browser = await launch();39const context = await browser.newContext();40const page = await context.newPage();41await page.click("input[name='q']");42await page.fill("input[name='q']", "Hello World!");43await page.press("input[name='q']", "Enter");44await page.screenshot({ path: `test.png` });45await browser.close();46await capture.stop();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { capture } = require("qawolf");2(async () => {3 await capture.stop();4})();5{6 "scripts": {7 },8 "dependencies": {9 }10}11 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)12 at Function.Module._load (internal/modules/cjs/loader.js:562:25)13 at Module.require (internal/modules/cjs/loader.js:692:17)14 at require (internal/modules/cjs/helpers.js:25:18)15 at Object.<anonymous> (/Users/.../test.js:1:18)16 at Module._compile (internal/modules/cjs/loader.js:778:30)17 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)18 at Module.load (internal/modules/cjs/loader.js:653:32)19 at tryModuleLoad (internal/modules/cjs/loader.js:593:12)20 at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { launch, devices } = require('qawolf');2const iPhone = devices['iPhone 6'];3const { capture } = require('qawolf');4(async () => {5 await capture.stop(browser);6})();7const { launch, devices } = require('qawolf');8const iPhone = devices['iPhone 6'];9const { capture } = require('qawolf');10(async () => {11 await capture.stop(browser);12})();13const { launch, devices } = require('qawolf');14const iPhone = devices['iPhone 6'];15const { capture } = require('qawolf');16(async () => {17 await capture.stop(browser);18})();19const { launch, devices } = require('qawolf');20const iPhone = devices['iPhone 6'];21const { capture } = require('qawolf');22(async () => {23 await capture.stop(browser);24})();25const { launch, devices } = require('qawolf');26const iPhone = devices['iPhone 6'];27const { capture } = require('qawolf');28(async () => {29 await capture.stop(browser);30})();31const { launch, devices } = require('qawolf');32const iPhone = devices['iPhone 6'];33const { capture } = require('qawolf');34(async () => {35 await capture.stop(browser);36})();37const { launch, devices } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const capture = require("qawolf");2const browser = await capture.launch();3const page = await browser.newPage();4await page.type("[name=q]", "Hello World");5await page.press("[name=q]", "Enter");6await capture.stop();7const capture = require("qawolf");8const browser = await capture.launch();9const page = await browser.newPage();10await page.type("[name=q]", "Hello World");11await page.press("[name=q]", "Enter");12await capture.stop();13The capture.stop() method is an async function, so you can use it in a test like this:14const capture = require("qawolf");15const browser = await capture.launch();16const page = await browser.newPage();17await page.type("[name=q]", "Hello World");18await page.press("[name=q]", "Enter");19await capture.stop();20If you want to stop the recording after a certain amount of time, you can use the capture.stopAfter() method:21const capture = require("qawolf");22const browser = await capture.launch();23const page = await browser.newPage();24await page.type("[name=q]", "Hello World");25await page.press("[name=q]", "Enter");26The capture.stopAfter() method is the correct way to stop the recording after a certain amount of

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful