Best JavaScript code snippet using ava
test.js
Source:test.js
1import {Buffer} from 'node:buffer';2import {promises as fs} from 'node:fs';3import path from 'node:path';4import test from '@ava/test';5import {cwd, fixture} from '../helpers/exec.js';6import {withTemporaryFixture} from '../helpers/with-temporary-fixture.js';7import {testSnapshotPruning} from './helpers/macros.js';8// To update the test fixture templates, run:9// npx test-ava test/snapshot-removal/** -- --update-fixture-snapshots10// Serial execution is used here solely to reduce the burden on CI machines.11test.serial('snapshots are removed when tests stop using them', testSnapshotPruning, {12 cwd: cwd('removal'),13 cli: ['--update-snapshots'],14 remove: true,15});16test.serial('snapshots are removed from a snapshot directory', testSnapshotPruning, {17 cwd: cwd('snapshot-dir'),18 cli: ['--update-snapshots'],19 remove: true,20 snapshotFile: path.join('test', 'snapshots', 'test.js.snap'),21 reportFile: path.join('test', 'snapshots', 'test.js.md'),22});23test.serial('snapshots are removed from a custom snapshotDir', testSnapshotPruning, {24 cwd: cwd('fixed-snapshot-dir'),25 cli: ['--update-snapshots'],26 remove: true,27 snapshotFile: path.join('fixedSnapshotDir', 'test.js.snap'),28 reportFile: path.join('fixedSnapshotDir', 'test.js.md'),29});30test.serial('removing non-existent snapshots doesn\'t throw', async t => {31 await withTemporaryFixture(cwd('no-snapshots'), async cwd => {32 // Execute fixture; this should try to unlink the nonexistent snapshots, and33 // should not throw34 const run = fixture(['--update-snapshots'], {35 cwd,36 env: {37 AVA_FORCE_CI: 'not-ci',38 },39 });40 await t.notThrowsAsync(run);41 });42});43test.serial('without --update-snapshots, invalid .snaps are retained', async t => {44 await withTemporaryFixture(cwd('no-snapshots'), async cwd => {45 const snapPath = path.join(cwd, 'test.js.snap');46 const invalid = Buffer.of(0x0A, 0x00, 0x00);47 await fs.writeFile(snapPath, invalid);48 await fixture([], {cwd});49 await t.notThrowsAsync(fs.access(snapPath));50 t.deepEqual(await fs.readFile(snapPath), invalid);51 });52});53test.serial('with --update-snapshots, invalid .snaps are removed', async t => {54 await withTemporaryFixture(cwd('no-snapshots'), async cwd => {55 const snapPath = path.join(cwd, 'test.js.snap');56 const invalid = Buffer.of(0x0A, 0x00, 0x00);57 await fs.writeFile(snapPath, invalid);58 await fixture(['--update-snapshots'], {cwd});59 await t.throwsAsync(fs.access(snapPath), {code: 'ENOENT'}, 'Expected snapshot to be removed');60 });61});62test.serial('snapshots remain if not updating', testSnapshotPruning, {63 cwd: cwd('removal'),64 cli: [],65 remove: false,66});67test.serial('snapshots remain if they are still used', testSnapshotPruning, {68 cwd: cwd('removal'),69 cli: ['--update-snapshots'],70 remove: false,71 env: {72 TEMPLATE: 'true',73 },74 async checkRun(t, run) {75 await t.notThrowsAsync(run, 'Expected fixture not to throw');76 const result = await run;77 t.snapshot(result.stats.passed, 'passed tests');78 },79});80test.serial('snapshots remain if tests run with --match', testSnapshotPruning, {81 cwd: cwd('removal'),82 cli: ['--update-snapshots', '--match=\'*another*\''],83 remove: false,84 async checkRun(t, run) {85 await t.notThrowsAsync(run, 'Expected fixture not to throw');86 const result = await run;87 t.snapshot(result.stats.passed, 'passed tests');88 },89});90test.serial('snapshots removed if --match selects all tests', testSnapshotPruning, {91 cwd: cwd('removal'),92 cli: ['--update-snapshots', '--match=\'*snapshot*\''],93 remove: true,94 async checkRun(t, run) {95 await t.notThrowsAsync(run, 'Expected fixture not to throw');96 const result = await run;97 t.snapshot(result.stats.passed, 'passed tests');98 },99});100test.serial('snapshots remain if tests selected by line numbers', testSnapshotPruning, {101 cwd: cwd('removal'),102 cli: ['test.js:10-17', '--update-snapshots'],103 remove: false,104 async checkRun(t, run) {105 await t.notThrowsAsync(run, 'Expected fixture not to throw');106 const result = await run;107 t.snapshot(result.stats.passed, 'passed tests');108 },109});110test.serial('snapshots removed if line numbers select all tests', testSnapshotPruning, {111 cwd: cwd('removal'),112 cli: ['test.js:0-100', '--update-snapshots'],113 remove: true,114 async checkRun(t, run) {115 await t.notThrowsAsync(run, 'Expected fixture not to throw');116 const result = await run;117 t.snapshot(result.stats.passed, 'passed tests');118 },119});120test.serial('snapshots remain if using test.only', testSnapshotPruning, {121 cwd: cwd('only-test'),122 cli: ['--update-snapshots'],123 remove: false,124 async checkRun(t, run) {125 await t.notThrowsAsync(run, 'Expected fixture not to throw');126 },127});128test.serial('snapshots remain if tests are skipped', testSnapshotPruning, {129 cwd: cwd('skipped-tests'),130 cli: ['--update-snapshots'],131 remove: false,132 async checkRun(t, run) {133 await t.notThrowsAsync(run, 'Expected fixture not to throw');134 },135});136test.serial('snapshots remain if snapshot assertions are skipped', testSnapshotPruning, {137 cwd: cwd('skipped-snapshots'),138 cli: ['--update-snapshots'],139 remove: false,140 async checkRun(t, run) {141 await t.notThrowsAsync(run, 'Expected fixture not to throw');142 },143});144// This behavior is consistent with the expectation that discarded attempts145// should have no effect.146test.serial('snapshots removed if used in a discarded try()', testSnapshotPruning, {147 cwd: cwd('try'),148 cli: ['--update-snapshots'],149 remove: true,150});151// This behavior is consistent with the expectation that discarded attempts152// should have no effect.153test.serial('snapshots removed if skipped in a discarded try()', testSnapshotPruning, {154 cwd: cwd('skipped-snapshots-in-try'),155 cli: ['--update-snapshots'],156 remove: true,157 async checkRun(t, run) {158 await t.notThrowsAsync(run, 'Expected fixture not to throw');159 },...
macros.js
Source:macros.js
...19 });20 };21}22module.exports.withTemporaryFixture = withTemporaryFixture;23async function testSnapshotPruning(t, {24 cwd,25 env,26 cli,27 remove,28 snapshotPath = 'test.js.snap',29 reportPath = 'test.js.md',30 checkRun = async (t, run) => {31 await t.notThrowsAsync(run, 'Expected fixture not to throw');32 }33}) {34 snapshotPath = path.join(cwd, snapshotPath);35 reportPath = path.join(cwd, reportPath);36 t.teardown(async () => {37 try {...
Using AI Code Generation
1const avalanche = require("avalanche");2const avm = require("avalanche/dist/apis/avm");3const binTools = avalanche.BinTools.getInstance();4const bintools = binTools;5const BN = avalanche.BN;6const avm = new avalanche.AVM();7const xchain = avm.XChain();
Using AI Code Generation
1const { Avalanche, BinTools, BN } = require("avalanche")2const { UnixNow } = require("avalanche/dist/utils")3const { Defaults } = require("avalanche/dist/utils")4const { AVMAPI } = require("avalanche/dist/apis/avm")5const { KeyChain } = require("avalanche/dist/utils")6const { PrivateKeyPrefix } = require("avalanche/dist/utils")7const { AVMConstants } = require("avalanche/dist/apis/avm")8const { iAVMUTXOResponse } = require("avalanche/dist/apis/avm/interfaces")9const { UTXOSet } = require("avalanche/dist/common")10const { TransferableInput } = require("avalanche/dist/apis/avm/inputs")11const { TransferableOutput } = require("avalanche/dist/apis/avm/outputs")12const { SECPTransferOutput } = require("avalanche/dist/apis/avm/outputs")13const { TransferableOperation } = require("avalanche/dist/apis/avm/tx")14const { UnsignedTx } = require("avalanche/dist/apis/avm/tx")15const { Tx } = require("avalanche/dist/apis/avm/tx")16const { Credential } = require("avalanche/dist/apis/avm")17const { InitialStates } = require("avalanche/dist/apis/avm")18const { AVMKeyChain } = require("avalanche/dist/apis/avm")19const { AVMU } = require("avalanche/dist/utils")20const { PayloadBase } = require("avalanche/dist/utils")21const { CreateAssetTx } = require("avalanche/dist/apis/avm/tx")22const { CreateAssetTx } = require("avalanche/dist/apis/avm/tx")23const { MintTx } = require("avalanche/dist/apis/avm/tx")24const { OperationTx } = require("avalanche/dist/apis/avm/tx")25const { ExportTx } = require("avalanche/dist/apis/avm/tx")26const { ImportTx } = require("avalanche/dist/apis/avm/tx")27const { ExportTx } = require("avalanche/dist/apis/avm/tx")28const { ImportTx } = require("avalanche/dist/apis/avm/tx")29const { UnsignedTx } = require("avalanche/dist/apis/avm/tx")30const { Tx } = require
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!!