How to use createTestBuffer method in wpt

Best JavaScript code snippet using wpt

pixel-differ.spec.ts

Source:pixel-differ.spec.ts Github

copy

Full Screen

...7describe('PixelDiffer', () => {8 describe('same width and height', () => {9 it('should compare identical buffers', async () => {10 const result = await new PixelDiffer().compare(11 await createTestBuffer(['RGB', 'RGB', 'RGB']),12 await createTestBuffer(['RGB', 'RGB', 'RGB'])13 );14 expect(result.matches).toBeTruthy();15 });16 it('should not create a diff for identical buffers', async () => {17 const result = await new PixelDiffer().compare(18 await createTestBuffer(['RGB', 'RGB', 'RGB']),19 await createTestBuffer(['RGB', 'RGB', 'RGB'])20 );21 expect(22 // @ts-expect-error because we don't discriminate the result23 result.diff24 ).toBeUndefined();25 });26 it('should not return the diff in percentage', async () => {27 const result = await new PixelDiffer().compare(28 await createTestBuffer(['RGB', 'RGB', 'RGB']),29 await createTestBuffer(['RGB', 'RGB', 'RGB'])30 );31 expect(32 // @ts-expect-error because we don't discriminate the result33 result.percentage34 ).toBeUndefined();35 });36 it('should compare different buffers', async () => {37 const result = await new PixelDiffer().compare(38 await createTestBuffer(['RRR', 'GGG', 'BBB']),39 await createTestBuffer(['GGG', 'BBB', 'RRR'])40 );41 expect(result.matches).toBeFalsy();42 });43 it('should create a diff for different buffers', async () => {44 const result = await new PixelDiffer().compare(45 await createTestBuffer(['GGG', 'GGG', 'GGG']),46 await createTestBuffer(['BBB', 'BBB', 'BBB'])47 );48 await expectIdenticalBuffers(49 // @ts-expect-error because we don't discriminate the result50 result.diff,51 await createTestBuffer(['RRR', 'RRR', 'RRR'])52 );53 });54 it('should return the diff in percentage', async () => {55 const baseline = await createTestBuffer(['GGG', 'GGG']);56 const tests: [[string, ...string[]], number][] = [57 [['BGG', 'GGG'], 16.67],58 [['BBG', 'GGG'], 33.33],59 [['BBB', 'GGG'], 50],60 [['BBB', 'BGG'], 66.67],61 [['BBB', 'BBG'], 83.34],62 [['BBB', 'BBB'], 100],63 ];64 // eslint-disable-next-line no-restricted-syntax65 for (const [test, result] of tests) {66 // eslint-disable-next-line no-await-in-loop67 const screenshot = await createTestBuffer(test);68 const {69 // @ts-expect-error because we don't discriminate the result70 percentage,71 // eslint-disable-next-line no-await-in-loop72 } = await new PixelDiffer().compare(baseline, screenshot);73 expect(percentage).toBeCloseTo(result, 0.01);74 }75 });76 it('should have 0 threshold by default', async () => {77 const result = await new PixelDiffer().compare(78 await createTestBuffer(['KKK', 'KKK']),79 await lightenBuffer(await createTestBuffer(['KKK', 'KKK']), 1)80 );81 expect(result.matches).toBeFalsy();82 });83 });84 // The target buffer is a subregion of the source buffer.85 describe('different sizes and same content', () => {86 it('with different width and height should create a diff', async () => {87 const result = await new PixelDiffer().compare(88 await createTestBuffer(['KKKK', 'KKKK']),89 await createTestBuffer(['KK', 'KK', 'KK', 'KK'])90 );91 expect(result.matches).toBeFalsy();92 await expectIdenticalBuffers(93 // @ts-expect-error because we don't discriminate the result94 result.diff,95 await createTestBuffer([' RR', ' RR', 'RR ', 'RR '])96 );97 });98 it('with different width should create a diff', async () => {99 const result = await new PixelDiffer().compare(100 await createTestBuffer(['KKK', 'KKK', 'KKK']),101 await createTestBuffer(['KK', 'KK', 'KK'])102 );103 expect(result.matches).toBeFalsy();104 await expectIdenticalBuffers(105 // @ts-expect-error because we don't discriminate the result106 result.diff,107 await createTestBuffer([' R', ' R', ' R'])108 );109 });110 it('with different height should create a diff', async () => {111 const result = await new PixelDiffer().compare(112 await createTestBuffer(['KKK', 'KKK', 'KKK']),113 await createTestBuffer(['KKK', 'KKK'])114 );115 expect(result.matches).toBeFalsy();116 await expectIdenticalBuffers(117 // @ts-expect-error because we don't discriminate the result118 result.diff,119 await createTestBuffer([' ', ' ', 'RRR'])120 );121 });122 it('should return the diff in percentage', async () => {123 const baseline = await createTestBuffer(['GGG', 'GGG']);124 const tests: [[string, ...string[]], number][] = [125 [['GGG'], 50],126 [['GGG', 'GGG', 'GGG'], 33.34],127 [['GGG', 'GGG', 'GGG', 'GGG'], 50],128 [['GGG', 'GGG', 'GGG', 'GGG', 'GGG'], 60],129 ];130 // eslint-disable-next-line no-restricted-syntax131 for (const [test, result] of tests) {132 // eslint-disable-next-line no-await-in-loop133 const screenshot = await createTestBuffer(test);134 const {135 // @ts-expect-error because we don't discriminate the result136 percentage,137 // eslint-disable-next-line no-await-in-loop138 } = await new PixelDiffer().compare(baseline, screenshot);139 expect(percentage).toBeCloseTo(result, 0.01);140 }141 });142 });143 describe('different sizes and different content', () => {144 it('with different width and height should create a diff', async () => {145 const result = await new PixelDiffer().compare(146 await createTestBuffer(['BB', 'BB']),147 await createTestBuffer(['GGG', 'GGG', 'GGG'])148 );149 expect(result.matches).toBeFalsy();150 await expectIdenticalBuffers(151 // @ts-expect-error because we don't discriminate the result152 result.diff,153 await createTestBuffer(['RRR', 'RRR', 'RRR'])154 );155 });156 it('with different width should create a diff', async () => {157 const result = await new PixelDiffer().compare(158 await createTestBuffer(['BBB', 'BBB', 'BBB']),159 await createTestBuffer(['GG', 'GG', 'GG'])160 );161 expect(result.matches).toBeFalsy();162 await expectIdenticalBuffers(163 // @ts-expect-error because we don't discriminate the result164 result.diff,165 await createTestBuffer(['RRR', 'RRR', 'RRR'])166 );167 });168 it('with different height should create a diff', async () => {169 const result = await new PixelDiffer().compare(170 await createTestBuffer(['BBB', 'BBB', 'BBB']),171 await createTestBuffer(['GGG', 'GGG'])172 );173 expect(result.matches).toBeFalsy();174 await expectIdenticalBuffers(175 // @ts-expect-error because we don't discriminate the result176 result.diff,177 await createTestBuffer(['RRR', 'RRR', 'RRR'])178 );179 });180 it('should return the diff in percentage', async () => {181 const baseline = await createTestBuffer(['GGG', 'GGG']);182 const tests: [[string, ...string[]], number][] = [183 [['BGG'], 66.67],184 [['BBG'], 83.34],185 [['BBB'], 100],186 [['BBB', 'BBB', 'BBB'], 100],187 [['BBB', 'BBB', 'BBB', 'BBB'], 100],188 [['BBB', 'BBB', 'BBB', 'BBB', 'BBB'], 100],189 ];190 // eslint-disable-next-line no-restricted-syntax191 for (const [test, result] of tests) {192 // eslint-disable-next-line no-await-in-loop193 const screenshot = await createTestBuffer(test);194 const {195 // @ts-expect-error because we don't discriminate the result196 percentage,197 // eslint-disable-next-line no-await-in-loop198 } = await new PixelDiffer().compare(baseline, screenshot);199 expect(percentage).toBeCloseTo(result, 0.01);200 }201 });202 });203 describe('config', () => {204 it('should apply custom diff color', async () => {205 const result = await new PixelDiffer({206 diffColor: { r: 0, g: 0, b: 255 },207 }).compare(208 await createTestBuffer(['RRR', 'RRR']),209 await createTestBuffer(['GGG', 'GGG'])210 );211 await expectIdenticalBuffers(212 // @ts-expect-error because we don't discriminate the result213 result.diff,214 await createTestBuffer(['BBB', 'BBB'])215 );216 });217 it('should apply custom diff color to non-intersecting areas', async () => {218 const result = await new PixelDiffer({219 diffColor: { r: 0, g: 0, b: 255 },220 }).compare(221 await createTestBuffer(['RRR', 'RRR']),222 await createTestBuffer(['GG', 'GG', 'GG'])223 );224 await expectIdenticalBuffers(225 // @ts-expect-error because we don't discriminate the result226 result.diff,227 await createTestBuffer(['BBB', 'BBB', 'BB '])228 );229 });230 it('should apply custom threshold', async () => {231 const result = await new PixelDiffer({ threshold: 0.1 }).compare(232 await createTestBuffer(['KKK', 'KKK']),233 await lightenBuffer(await createTestBuffer(['KKK', 'KKK']), 10)234 );235 expect(result.matches).toBeTruthy();236 });237 });...

Full Screen

Full Screen

track-parser-test.ts

Source:track-parser-test.ts Github

copy

Full Screen

...78describe('TrackParser: constructor', () => {910 it('buffer should not be empty', () => {11 let tp = new TrackParser(createTestBuffer());12 const result = tp.getBuffer !== undefined;13 expect(result).to.equal(true);14 });15 it('offset should start at 0', () => {16 let tp = new TrackParser(createTestBuffer());17 const result = tp.getOffset();18 expect(result).to.equal(0);19 });20 it('track should contain events', () => {21 let tp = new TrackParser(createTestBuffer());22 let track = tp.parse();23 const result = track.isEmpty();24 expect(result).to.equal(false);25 });26});2728describe('TrackParser: low level functions', () => {29 it('getBuffer should not be empty', () => {30 let tp = new TrackParser(createTestBuffer());31 const result = tp.getBuffer() !== undefined;32 expect(result).to.equal(true);33 });34 it('getOffset should start at 0', () => {35 let tp = new TrackParser(createTestBuffer());36 const result = tp.getOffset() === 0;37 expect(result).to.equal(true);38 });39 it('peekUInt8(pos) should read 1 Byte at offset + pos without changing the offset', () => {40 let tp = new TrackParser(createTestBuffer());41 let result = tp.peekUInt8(0);42 expect(result).to.equal(0);43 result = tp.getOffset();44 expect(result).to.equal(0);45 });46 it('readUInt32(pos) should read 4 Bytes at current offset and add 4 to offset', () => {47 let tp = new TrackParser(createTestBuffer());48 let result = tp.readUInt32();49 expect(result).to.equal(37);50 result = tp.getOffset();51 expect(result).to.equal(4);52 });53 it('extractRawTime() should read variable size bytes', () => {54 let tp = new TrackParser(Buffer.from([189,132,64]));55 let result = tp.extractRawTime();56 expect(result[0]).to.equal(189);57 expect(result[1]).to.equal(132);58 expect(result[2]).to.equal(64);59 expect(result.length).to.equal(3);60 });61 it('extractSize() should read variable size number', () => {62 let tp = new TrackParser(Buffer.from([189,132,64]));63 let result = tp.extractSize();64 expect(result).to.equal(1000000);65 });66 it('reset() should reset the buffer offset to zero', () => {67 let tp = new TrackParser(Buffer.from([189,132,64]));68 tp.extractSize();69 expect(tp.getOffset() > 0).to.equal(true);70 tp.reset();71 expect(tp.getOffset()).to.equal(0);72 });73});7475describe('TrackParser: mid level functions', () => {76 it('extractMetaEvent should return correct MetaEvent', () => {77 let tp = new TrackParser(Buffer.from([10,1,127]));78 const result = tp.extractMetaEvent(0);79 expect(result!== undefined).to.equal(true);80 if (result!== undefined){81 expect(result.type).to.equal(10);82 expect(result.time[0]).to.equal(0);83 expect(Array.isArray(result.data)).to.equal(true);84 if (Array.isArray(result.data)){85 expect(result.data[0]).to.equal(127);86 } else {87 expect(result!== undefined).to.equal(true);88 }89 }90 });91 it('extractMidiEventData should return correct array (filled with zeroes if less than 2 bytes)', () => {92 let tp = new TrackParser(Buffer.from([127]));93 const result = tp.extractMidiEventData(MidiEvent.PROGRAM_CHANGE);94 expect(result!== undefined).to.equal(true);95 if (result!== undefined){96 expect(result[0]).to.equal(127);97 }98 });99 it('extractMidiEvent should not create events for unsupported events', () => {100 let tp = new TrackParser(Buffer.from([12,13]));101 const result = tp.extractMidiEvent(0x71,10);102 expect(result=== undefined).to.equal(true);103 });104105});106107108function createTestBuffer(): Buffer {109 let mt: MidiTrack = new MidiTrack();110 mt.addArpeggiatedChord(1, ['c4', 'e4', 'a4', 'c5'], 200, 5, 10, 90);111 let buffer = Buffer.from(mt.toBytes().slice(4));112 return buffer113}114function createMetaEventsTestBuffer(): Buffer {115 let mt: MidiTrack = new MidiTrack();116 mt.addEvent(new MetaEvent({time:0,type:MetaEvent.SEQUENCE,data:1}));117 mt.addEvent(new MetaEvent({time:0,type:MetaEvent.COPYRIGHT,data:'(c) tsmidgen 2020'}));118 mt.addArpeggiatedChord(1, ['c4', 'e4', 'a4', 'c5'], 200, 5, 10, 90);119 let buffer = Buffer.from(mt.toBytes().slice(4));120 return buffer ...

Full Screen

Full Screen

file-parser-test.ts

Source:file-parser-test.ts Github

copy

Full Screen

...6import { MidiUtil } from '../src/midi-util';78describe('FileParser: checkFileHeader', () => {9 it('correct file header should return true', () => {10 let fp = new FileParser(createTestBuffer());11 expect(fp.checkFileHeader()).to.equal(true);12 });13 it('incorrect file header should throw exception (first 4 bytes)', () => {14 let fp = new FileParser(createIncorrectBuffer1());15 expect(() => fp.checkFileHeader()).to.throw(FileParser.ERROR_MSG);16 });17 it('incorrect file header should throw exception (next 4 bytes)', () => {18 let fp = new FileParser(createIncorrectBuffer2());19 expect(() => fp.checkFileHeader()).to.throw(FileParser.ERROR_MSG);20 });21});2223describe('FileParser: parse', () => {24 it('check that parsing works fine', () => {25 let originalBuffer = createTestBuffer();26 let fp = new FileParser(originalBuffer);27 let mf = fp.parseFile();28 let buffer = Buffer.from(mf.toBytes(),'binary');29 expect(buffer.toString()).to.equal(originalBuffer.toString());30 });31 it('check that empty tracks are removed', () => {32 const EmptyTrack = [0x4d, 0x54, 0x72, 0x6b, 0x00, 0x00, 0x00, 0x04, 0x00, 0xFF, 0x2F, 0x00];33 let originalBuffer = createTestBuffer(EmptyTrack);34 let fp = new FileParser(originalBuffer);35 let mf = fp.parseFile();36 let buffer = Buffer.from(mf.toBytes() ,'binary');37 expect(buffer.toString()).to.equal(createTestBuffer().toString());38 });39 it('unexpected bytes are ignored', () => {40 const emptyTrack = [0x4d, 0x54, 0x72, 0x6b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0xFF, 0x2F, 0x00];41 let originalBuffer = createTestBuffer(emptyTrack);42 let fp = new FileParser(originalBuffer);43 let mf = fp.parseFile();44 let buffer = Buffer.from(mf.toBytes() ,'binary');45 expect(buffer.toString()).to.equal(createTestBuffer().toString());46 });47});4849function createTestBuffer(additionalData?: number[]): Buffer{50 let mf = new MidiFile();51 let mt = new MidiTrack();52 let ad = '';53 if(additionalData){54 ad = MidiUtil.codes2Str(additionalData);55 }56 mt.addNote(1,60,127,0,80);57 mf.addTrack(mt);58 mf.addTrack(mt);59 let file: string = mf.toBytes();60 file += ad;61 let buffer = Buffer.from(file,'binary');62 return buffer63} ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt-api');2wpt.createTest(testBuffer, 'test', (err, data) => {3 if (err) {4 console.log('error creating test');5 console.log(err);6 } else {7 console.log('test created');8 console.log(data);9 wpt.getTest(data.data.id, (err, data) => {10 if (err) {11 console.log('error getting test');12 console.log(err);13 } else {14 console.log('test retrieved');15 console.log(data);16 wpt.deleteTest(data.data.id, (err, data) => {17 if (err) {18 console.log('error deleting test');19 console.log(err);20 } else {21 console.log('test deleted');22 console.log(data);23 }24 });25 }26 });27 }28});29- `runs` - The number of test runs to complete (default: 1)30- `fvonly` - First View only test (default: false)31- `location` - The location to run the test from (default: 'ec2-us-west-1:Chrome')32- `connectivity` - The connectivity profile to use for the test (default: 'Cable')33- `bwDown` - The download bandwidth in Kbps (default: 0)34- `bwUp` - The upload bandwidth in Kbps (default: 0)35- `latency` - The latency in ms (default: 0)36- `plr` - The packet loss rate in % (default: 0)37- `mobile` - Mobile device emulation (default: false)38- `timeline` - Capture a timeline trace (default: false)39- `video` - Capture a video of the test (default: false)40- `spof` - Simulate a single point of failure (default: false)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var api = new wpt('A.2c1e1f4d4c8d8b2c2d1f1d1b1b1f1f1b');3var options = {4 lighthouseConfig: {5 "settings": {6 }7 },8};9api.createTestBuffer(options, function (err, data) {10 if (err) return console.error(err);11 console.log(data);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var test = new wpt(options);5test.createTestBuffer(testURL, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});

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 wpt 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