Best JavaScript code snippet using playwright-internal
resolver.js
Source: resolver.js
2var test = require('tape');3var resolve = require('../');4test('async foo', function (t) {5 t.plan(12);6 var dir = path.join(__dirname, 'resolver');7 resolve('./foo', { basedir: dir }, function (err, res, pkg) {8 if (err) t.fail(err);9 t.equal(res, path.join(dir, 'foo.js'));10 t.equal(pkg && pkg.name, 'resolve');11 });12 resolve('./foo.js', { basedir: dir }, function (err, res, pkg) {13 if (err) t.fail(err);14 t.equal(res, path.join(dir, 'foo.js'));15 t.equal(pkg && pkg.name, 'resolve');16 });17 resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {18 if (err) t.fail(err);19 t.equal(res, path.join(dir, 'foo.js'));20 t.equal(pkg && pkg.main, 'resolver');21 });22 resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {23 if (err) t.fail(err);24 t.equal(res, path.join(dir, 'foo.js'));25 t.equal(pkg.main, 'resolver');26 });27 resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) {28 if (err) t.fail(err);29 t.equal(res, path.join(dir, 'foo.js'));30 });31 resolve('foo', { basedir: dir }, function (err) {32 t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");33 t.equal(err.code, 'MODULE_NOT_FOUND');34 });35 // Test that filename is reported as the "from" value when passed.36 resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) {37 t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'");38 });39});40test('bar', function (t) {41 t.plan(6);42 var dir = path.join(__dirname, 'resolver');43 resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {44 if (err) t.fail(err);45 t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));46 t.equal(pkg, undefined);47 });48 resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {49 if (err) t.fail(err);50 t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));51 t.equal(pkg, undefined);52 });53 resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) {54 if (err) t.fail(err);55 t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));56 t.equal(pkg.main, 'bar');57 });58});59test('baz', function (t) {60 t.plan(4);61 var dir = path.join(__dirname, 'resolver');62 resolve('./baz', { basedir: dir }, function (err, res, pkg) {63 if (err) t.fail(err);64 t.equal(res, path.join(dir, 'baz/quux.js'));65 t.equal(pkg.main, 'quux.js');66 });67 resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {68 if (err) t.fail(err);69 t.equal(res, path.join(dir, 'baz/quux.js'));70 t.equal(pkg.main, 'quux.js');71 });72});73test('biz', function (t) {74 t.plan(24);75 var dir = path.join(__dirname, 'resolver/biz/node_modules');76 resolve('./grux', { basedir: dir }, function (err, res, pkg) {77 if (err) t.fail(err);78 t.equal(res, path.join(dir, 'grux/index.js'));79 t.equal(pkg, undefined);80 });81 resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {82 if (err) t.fail(err);83 t.equal(res, path.join(dir, 'grux/index.js'));84 t.equal(pkg.main, 'biz');85 });86 resolve('./garply', { basedir: dir }, function (err, res, pkg) {87 if (err) t.fail(err);88 t.equal(res, path.join(dir, 'garply/lib/index.js'));89 t.equal(pkg.main, './lib');90 });91 resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {92 if (err) t.fail(err);93 t.equal(res, path.join(dir, 'garply/lib/index.js'));94 t.equal(pkg.main, './lib');95 });96 resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) {97 if (err) t.fail(err);98 t.equal(res, path.join(dir, 'tiv/index.js'));99 t.equal(pkg, undefined);100 });101 resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) {102 if (err) t.fail(err);103 t.equal(res, path.join(dir, 'tiv/index.js'));104 t.equal(pkg.main, 'grux');105 });106 resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) {107 if (err) t.fail(err);108 t.equal(res, path.join(dir, 'tiv/index.js'));109 t.equal(pkg, undefined);110 });111 resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) {112 if (err) t.fail(err);113 t.equal(res, path.join(dir, 'tiv/index.js'));114 t.equal(pkg.main, './lib');115 });116 resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) {117 if (err) t.fail(err);118 t.equal(res, path.join(dir, 'grux/index.js'));119 t.equal(pkg, undefined);120 });121 resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {122 if (err) t.fail(err);123 t.equal(res, path.join(dir, 'grux/index.js'));124 t.equal(pkg.main, 'tiv');125 });126 resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) {127 if (err) t.fail(err);128 t.equal(res, path.join(dir, 'garply/lib/index.js'));129 t.equal(pkg.main, './lib');130 });131 resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {132 if (err) t.fail(err);133 t.equal(res, path.join(dir, 'garply/lib/index.js'));134 t.equal(pkg.main, './lib');135 });136});137test('quux', function (t) {138 t.plan(2);139 var dir = path.join(__dirname, 'resolver/quux');140 resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) {141 if (err) t.fail(err);142 t.equal(res, path.join(dir, 'foo/index.js'));143 t.equal(pkg.main, 'quux');144 });145});146test('normalize', function (t) {147 t.plan(2);148 var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');149 resolve('../grux', { basedir: dir }, function (err, res, pkg) {150 if (err) t.fail(err);151 t.equal(res, path.join(dir, 'index.js'));152 t.equal(pkg, undefined);153 });154});155test('cup', function (t) {156 t.plan(5);157 var dir = path.join(__dirname, 'resolver');158 resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {159 if (err) t.fail(err);160 t.equal(res, path.join(dir, 'cup.coffee'));161 });162 resolve('./cup.coffee', { basedir: dir }, function (err, res) {163 if (err) t.fail(err);164 t.equal(res, path.join(dir, 'cup.coffee'));165 });166 resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) {167 t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");168 t.equal(err.code, 'MODULE_NOT_FOUND');169 });170 // Test that filename is reported as the "from" value when passed.171 resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) {172 t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'");173 });174});175test('mug', function (t) {176 t.plan(3);177 var dir = path.join(__dirname, 'resolver');178 resolve('./mug', { basedir: dir }, function (err, res) {179 if (err) t.fail(err);180 t.equal(res, path.join(dir, 'mug.js'));181 });182 resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) {183 if (err) t.fail(err);184 t.equal(res, path.join(dir, '/mug.coffee'));185 });186 resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {187 t.equal(res, path.join(dir, '/mug.js'));188 });189});190test('other path', function (t) {191 t.plan(6);192 var resolverDir = path.join(__dirname, 'resolver');193 var dir = path.join(resolverDir, 'bar');194 var otherDir = path.join(resolverDir, 'other_path');195 resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) {196 if (err) t.fail(err);197 t.equal(res, path.join(resolverDir, 'other_path/root.js'));198 });199 resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) {200 if (err) t.fail(err);201 t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js'));202 });203 resolve('root', { basedir: dir }, function (err, res) {204 t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");205 t.equal(err.code, 'MODULE_NOT_FOUND');206 });207 resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) {208 t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");209 t.equal(err.code, 'MODULE_NOT_FOUND');210 });211});212test('path iterator', function (t) {213 t.plan(2);214 var resolverDir = path.join(__dirname, 'resolver');215 var exactIterator = function (x, start, getPackageCandidates, opts) {216 return [path.join(resolverDir, x)];217 };218 resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {219 if (err) t.fail(err);220 t.equal(res, path.join(resolverDir, 'baz/quux.js'));221 t.equal(pkg && pkg.name, 'baz');222 });223});224test('incorrect main', function (t) {225 t.plan(1);226 var resolverDir = path.join(__dirname, 'resolver');227 var dir = path.join(resolverDir, 'incorrect_main');228 resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) {229 if (err) t.fail(err);230 t.equal(res, path.join(dir, 'index.js'));231 });232});233test('without basedir', function (t) {234 t.plan(1);235 var dir = path.join(__dirname, 'resolver/without_basedir');236 var tester = require(path.join(dir, 'main.js'));237 tester(t, function (err, res, pkg) {238 if (err) {239 t.fail(err);240 } else {241 t.equal(res, path.join(dir, 'node_modules/mymodule.js'));242 }243 });244});245test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {246 t.plan(2);247 var dir = path.join(__dirname, 'resolver');248 resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {249 if (err) t.fail(err);250 t.equal(res, path.join(dir, 'same_names/foo.js'));251 });252 resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {253 if (err) t.fail(err);254 t.equal(res, path.join(dir, 'same_names/foo/index.js'));255 });256});257test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) {258 t.plan(2);259 var dir = path.join(__dirname, 'resolver');260 resolve('./', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {261 if (err) t.fail(err);262 t.equal(res, path.join(dir, 'same_names/foo/index.js'));263 });264 resolve('.', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {265 if (err) t.fail(err);266 t.equal(res, path.join(dir, 'same_names/foo/index.js'));267 });268});269test('async: #121 - treating an existing file as a dir when no basedir', function (t) {270 var testFile = path.basename(__filename);271 t.test('sanity check', function (st) {272 st.plan(1);273 resolve('./' + testFile, function (err, res, pkg) {274 if (err) t.fail(err);275 st.equal(res, __filename, 'sanity check');276 });277 });278 t.test('with a fake directory', function (st) {279 st.plan(4);280 resolve('./' + testFile + '/blah', function (err, res, pkg) {281 st.ok(err, 'there is an error');282 st.notOk(res, 'no result');283 st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');284 st.equal(285 err && err.message,286 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',287 'can not find nonexistent module'288 );289 st.end();290 });291 });292 t.end();293});294test('async dot main', function (t) {295 var start = new Date();296 t.plan(3);297 resolve('./resolver/dot_main', function (err, ret) {298 t.notOk(err);299 t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js'));300 t.ok(new Date() - start < 50, 'resolve.sync timedout');301 t.end();302 });303});304test('async dot slash main', function (t) {305 var start = new Date();306 t.plan(3);307 resolve('./resolver/dot_slash_main', function (err, ret) {308 t.notOk(err);309 t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js'));310 t.ok(new Date() - start < 50, 'resolve.sync timedout');311 t.end();312 });313});314test('not a directory', function (t) {315 t.plan(6);316 var path = './foo';317 resolve(path, { basedir: __filename }, function (err, res, pkg) {318 t.ok(err, 'a non-directory errors');319 t.equal(arguments.length, 1);320 t.equal(res, undefined);321 t.equal(pkg, undefined);322 t.equal(err && err.message, 'Cannot find module \'' + path + '\' from \'' + __filename + '\'');323 t.equal(err && err.code, 'MODULE_NOT_FOUND');324 });325});326test('non-string "main" field in package.json', function (t) {327 t.plan(5);328 var dir = path.join(__dirname, 'resolver');329 resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {330 t.ok(err, 'errors on non-string main');331 t.equal(err.message, 'package âinvalid mainâ `main` must be a string');332 t.equal(err.code, 'INVALID_PACKAGE_MAIN');333 t.equal(res, undefined, 'res is undefined');334 t.equal(pkg, undefined, 'pkg is undefined');335 });336});337test('non-string "main" field in package.json', function (t) {338 t.plan(5);339 var dir = path.join(__dirname, 'resolver');340 resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {341 t.ok(err, 'errors on non-string main');342 t.equal(err.message, 'package âinvalid mainâ `main` must be a string');343 t.equal(err.code, 'INVALID_PACKAGE_MAIN');344 t.equal(res, undefined, 'res is undefined');345 t.equal(pkg, undefined, 'pkg is undefined');346 });347});348test('browser field in package.json', function (t) {349 t.plan(3);350 var dir = path.join(__dirname, 'resolver');351 resolve(352 './browser_field',353 {354 basedir: dir,355 packageFilter: function packageFilter(pkg) {356 if (pkg.browser) {357 pkg.main = pkg.browser; // eslint-disable-line no-param-reassign358 delete pkg.browser; // eslint-disable-line no-param-reassign359 }360 return pkg;361 }362 },363 function (err, res, pkg) {364 if (err) t.fail(err);365 t.equal(res, path.join(dir, 'browser_field', 'b.js'));366 t.equal(pkg && pkg.main, 'b');367 t.equal(pkg && pkg.browser, undefined);368 }369 );...
wbuf-test.js
Source: wbuf-test.js
...4 var w;5 beforeEach(function() {6 w = new WriteBuffer();7 });8 function join(arr) {9 return arr.map(function(buf) {10 return buf.toString('hex');11 }).join('');12 }13 describe('.writeUInt8', function() {14 it('should write bytes', function() {15 w.writeUInt8(1);16 w.writeUInt8(2);17 w.writeUInt8(3);18 w.writeUInt8(4);19 assert.equal(join(w.render()), '01020304');20 });21 it('should correctly handle overflow', function() {22 w.reserve(3);23 w.writeUInt8(1);24 w.writeUInt8(2);25 w.writeUInt8(3);26 w.writeUInt8(4);27 assert.equal(join(w.render()), '01020304');28 });29 });30 describe('.writeInt8', function() {31 it('should write bytes', function() {32 w.writeInt8(-1);33 w.writeInt8(2);34 assert.equal(join(w.render()), 'ff02');35 });36 });37 describe('.writeUInt16BE', function() {38 it('should write bytes', function() {39 w.writeUInt16BE(0x0102);40 w.writeUInt16BE(0x0304);41 assert.equal(join(w.render()), '01020304');42 });43 it('should correctly handle overflow', function() {44 w.reserve(2);45 w.reserve(3);46 w.writeUInt16BE(0x0102);47 w.writeUInt16BE(0x0304);48 w.writeUInt16BE(0x0506);49 assert.equal(join(w.render()), '010203040506');50 });51 });52 describe('.writeInt16BE', function() {53 it('should write bytes', function() {54 w.writeInt16BE(-0x0102);55 w.writeInt16BE(0x0304);56 assert.equal(join(w.render()), 'fefe0304');57 });58 });59 describe('.writeUInt16LE', function() {60 it('should write bytes', function() {61 w.writeUInt16LE(0x0102);62 w.writeUInt16LE(0x0304);63 assert.equal(join(w.render()), '02010403');64 });65 it('should correctly handle overflow', function() {66 w.reserve(2);67 w.reserve(3);68 w.writeUInt16LE(0x0102);69 w.writeUInt16LE(0x0304);70 w.writeUInt16LE(0x0506);71 assert.equal(join(w.render()), '020104030605');72 });73 });74 describe('.writeInt16LE', function() {75 it('should write bytes', function() {76 w.writeInt16LE(-0x0201);77 w.writeInt16LE(0x0304);78 assert.equal(join(w.render()), 'fffd0403');79 });80 });81 describe('.writeUInt24BE', function() {82 it('should write bytes', function() {83 w.writeUInt24BE(0x010203);84 w.writeUInt24BE(0x040506);85 assert.equal(join(w.render()), '010203040506');86 });87 it('should correctly set avail on boundary', function() {88 w = new WriteBuffer();89 w.reserveRate = 4;90 w.writeUInt16BE(1);91 w.writeUInt24BE(1);92 assert.equal(w.avail, 3);93 });94 });95 describe('.writeInt24BE', function() {96 it('should write bytes', function() {97 w.writeInt24BE(-0x010203);98 w.writeInt24BE(0x040506);99 assert.equal(join(w.render()), 'fefdfd040506');100 });101 });102 describe('.writeUInt24LE', function() {103 it('should write bytes', function() {104 w.writeUInt24LE(0x010203);105 w.writeUInt24LE(0x040506);106 assert.equal(join(w.render()), '030201060504');107 });108 });109 describe('.writeInt24LE', function() {110 it('should write bytes', function() {111 w.writeInt24LE(-0x010203);112 w.writeInt24LE(0x040506);113 assert.equal(join(w.render()), 'fdfdfe060504');114 });115 });116 describe('.writeUInt32BE', function() {117 it('should write bytes', function() {118 w.writeUInt32BE(0x01020304);119 w.writeUInt32BE(0x05060708);120 assert.equal(join(w.render()), '0102030405060708');121 });122 it('should write bytes on the boundary', function() {123 w.reserve(4);124 w.writeUInt8(0x00);125 w.writeUInt32BE(0x01020304);126 assert.equal(join(w.render()), '0001020304');127 });128 });129 describe('.writeInt32BE', function() {130 it('should write bytes', function() {131 w.writeInt32BE(-0x01020304);132 w.writeInt32BE(0x05060708);133 assert.equal(join(w.render()), 'fefdfcfc05060708');134 });135 });136 describe('.writeUInt32LE', function() {137 it('should write bytes', function() {138 w.writeUInt32LE(0x01020304);139 w.writeUInt32LE(0x05060708);140 assert.equal(join(w.render()), '0403020108070605');141 });142 it('should write max uint32 value', function() {143 w.writeUInt32LE(0xffffffff);144 assert.equal(join(w.render()), 'ffffffff');145 });146 });147 describe('.combWrite', function() {148 it('should write bytes', function() {149 w.writeComb(1, 'le', 0x01);150 w.writeComb(1, 'be', 0x02);151 w.writeComb(2, 'le', 0x0102);152 w.writeComb(2, 'be', 0x0304);153 w.writeComb(3, 'le', 0x010203);154 w.writeComb(3, 'be', 0x040506);155 w.writeComb(4, 'le', 0x01020304);156 w.writeComb(4, 'be', 0x05060708);157 assert.equal(join(w.render()),158 '0102020103040302010405060403020105060708');159 });160 it('should write max uint32 value', function() {161 w.writeUInt32LE(0xffffffff);162 assert.equal(join(w.render()), 'ffffffff');163 });164 });165 describe('.writeInt32LE', function() {166 it('should write bytes', function() {167 w.writeInt32LE(-0x01020304);168 w.writeInt32LE(0x05060708);169 assert.equal(join(w.render()), 'fcfcfdfe08070605');170 });171 });172 describe('.skip', function() {173 it('should skip bytes', function() {174 w.skip(4);175 w.writeUInt32BE(0xdeadbeef);176 assert(/^.{8}deadbeef$/.test(join(w.render())));177 });178 it('should skip 0 bytes', function() {179 var skip = w.skip(0);180 assert.equal(skip.size, 0);181 w.writeUInt32BE(0xdeadbeef);182 assert(/^deadbeef$/.test(join(w.render())));183 });184 it('should skip bytes on the boundary', function() {185 w.reserve(4);186 w.writeUInt8(0x01);187 var skip = w.skip(4);188 w.writeUInt32BE(0xdeadbeef);189 skip.writeUInt32BE(0xabbabaab);190 assert(/^01abbabaabdeadbeef$/.test(join(w.render())));191 });192 it('should skip bytes on the boundary in two chunks', function() {193 w.reserve(4);194 var skip1 = w.skip(2);195 var skip2 = w.skip(2);196 w.writeUInt32BE(0xdeadbeef);197 skip1.writeUInt16BE(0xabba);198 skip2.writeUInt16BE(0xbaba);199 assert(/^abbababadeadbeef$/.test(join(w.render())));200 });201 });202 describe('.slice', function() {203 it('should return empty slice', function() {204 w.writeUInt32BE(0xabbadead);205 assert.equal(join(w.slice(4, 4).render()), '');206 assert.equal(join(w.render()), 'abbadead');207 });208 it('should return full slice', function() {209 w.writeUInt32BE(0xabbadead);210 var slice = w.slice(0, 4);211 slice.writeUInt32BE(0xdeadbeef);212 assert.equal(join(slice.render()), 'deadbeef');213 assert.equal(join(w.render()), 'deadbeef');214 });215 it('should return partial slice', function() {216 w.writeUInt32BE(0xabbadead);217 var slice = w.slice(0, 3);218 slice.writeUInt24BE(0xdeadbe);219 assert.equal(join(slice.render()), 'deadbe');220 assert.equal(join(w.render()), 'deadbead');221 });222 it('should return over-the-boundary slice', function() {223 for (var i = 0; i < 16; i++) {224 w.reserve(3);225 w.writeUInt24BE(i);226 }227 assert.equal(join(w.render()),228 '000000000001000002000003000004000005000006000007' +229 '00000800000900000a00000b00000c00000d00000e00000f');230 var slice = w.slice(5, 12);231 slice.writeUInt24BE(0xaaabac);232 slice.writeUInt24BE(0xbabbbc);233 slice.writeUInt8(0xcc);234 assert.equal(join(slice.render()), 'aaabacbabbbccc');235 assert.equal(join(w.render()),236 '0000000000aaabacbabbbccc000004000005000006000007' +237 '00000800000900000a00000b00000c00000d00000e00000f');238 });239 });240 describe('.copyFrom', function() {241 it('should copy bytes', function() {242 var tmp = new Buffer(128);243 for (var i = 0; i < tmp.length; i++)244 tmp[i] = i;245 w.writeUInt32BE(0xdeadbeef);246 w.copyFrom(tmp);247 w.writeUInt32BE(0xabbadead);248 assert.equal(249 join(w.render()),250 'deadbeef000102030405060708090a0b0c0d0e0f101112131415161718191a1b' +251 '1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b' +252 '3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b' +253 '5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b' +254 '7c7d7e7fabbadead');255 });256 it('should copy bytes using offset', function() {257 var tmp = new Buffer(128);258 for (var i = 0; i < tmp.length; i++)259 tmp[i] = i;260 w.writeUInt32BE(0xdeadbeef);261 w.copyFrom(tmp, 10, 12);262 w.writeUInt32BE(0xabbadead);263 assert.equal(264 join(w.render()),265 'deadbeef0a0babbadead');266 });267 });268 describe('.write', function() {269 it('should write utf8 string', function() {270 w.writeUInt32BE(0xdeadbeef);271 w.write('ohai\u1023');272 w.writeUInt32BE(0xabbadead);273 assert.equal(274 join(w.render()),275 'deadbeef' +276 '6f6861691023' +277 'abbadead');278 });279 it('should copy bytes using offset', function() {280 var tmp = new Buffer(128);281 for (var i = 0; i < tmp.length; i++)282 tmp[i] = i;283 w.writeUInt32BE(0xdeadbeef);284 w.copyFrom(tmp, 10, 12);285 w.writeUInt32BE(0xabbadead);286 assert.equal(287 join(w.render()),288 'deadbeef0a0babbadead');289 });290 });291 describe('.skip', function() {292 it('should copy bytes', function() {293 w.reserve(5);294 var h = w.skip(4);295 w.writeUInt32BE(0xabbadead);296 h.writeUInt32BE(0xdeadbeef);297 assert.equal(298 join(w.render()),299 'deadbeefabbadead');300 });301 });302 describe('.forceReserve = true', function() {303 it('should allocate more bytes', function() {304 w.forceReserve = true;305 w.reserve(4);306 w.writeUInt32BE(0xabbadead);307 w.writeUInt32BE(0xabbadead);308 assert.equal(w.render().length, 1);309 });310 });...
resolver_sync.js
Source: resolver_sync.js
1var path = require('path');2var test = require('tape');3var resolve = require('../');4test('foo', function (t) {5 var dir = path.join(__dirname, 'resolver');6 t.equal(7 resolve.sync('./foo', { basedir: dir }),8 path.join(dir, 'foo.js')9 );10 t.equal(11 resolve.sync('./foo.js', { basedir: dir }),12 path.join(dir, 'foo.js')13 );14 t.equal(15 resolve.sync('./foo.js', { basedir: dir, filename: path.join(dir, 'bar.js') }),16 path.join(dir, 'foo.js')17 );18 t.throws(function () {19 resolve.sync('foo', { basedir: dir });20 });21 // Test that filename is reported as the "from" value when passed.22 t.throws(23 function () {24 resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') });25 },26 {27 name: 'Error',28 message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'"29 }30 );31 t.end();32});33test('bar', function (t) {34 var dir = path.join(__dirname, 'resolver');35 t.equal(36 resolve.sync('foo', { basedir: path.join(dir, 'bar') }),37 path.join(dir, 'bar/node_modules/foo/index.js')38 );39 t.end();40});41test('baz', function (t) {42 var dir = path.join(__dirname, 'resolver');43 t.equal(44 resolve.sync('./baz', { basedir: dir }),45 path.join(dir, 'baz/quux.js')46 );47 t.end();48});49test('biz', function (t) {50 var dir = path.join(__dirname, 'resolver/biz/node_modules');51 t.equal(52 resolve.sync('./grux', { basedir: dir }),53 path.join(dir, 'grux/index.js')54 );55 t.equal(56 resolve.sync('tiv', { basedir: path.join(dir, 'grux') }),57 path.join(dir, 'tiv/index.js')58 );59 t.equal(60 resolve.sync('grux', { basedir: path.join(dir, 'tiv') }),61 path.join(dir, 'grux/index.js')62 );63 t.end();64});65test('normalize', function (t) {66 var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');67 t.equal(68 resolve.sync('../grux', { basedir: dir }),69 path.join(dir, 'index.js')70 );71 t.end();72});73test('cup', function (t) {74 var dir = path.join(__dirname, 'resolver');75 t.equal(76 resolve.sync('./cup', {77 basedir: dir,78 extensions: ['.js', '.coffee']79 }),80 path.join(dir, 'cup.coffee')81 );82 t.equal(83 resolve.sync('./cup.coffee', { basedir: dir }),84 path.join(dir, 'cup.coffee')85 );86 t.throws(function () {87 resolve.sync('./cup', {88 basedir: dir,89 extensions: ['.js']90 });91 });92 t.end();93});94test('mug', function (t) {95 var dir = path.join(__dirname, 'resolver');96 t.equal(97 resolve.sync('./mug', { basedir: dir }),98 path.join(dir, 'mug.js')99 );100 t.equal(101 resolve.sync('./mug', {102 basedir: dir,103 extensions: ['.coffee', '.js']104 }),105 path.join(dir, 'mug.coffee')106 );107 t.equal(108 resolve.sync('./mug', {109 basedir: dir,110 extensions: ['.js', '.coffee']111 }),112 path.join(dir, 'mug.js')113 );114 t.end();115});116test('other path', function (t) {117 var resolverDir = path.join(__dirname, 'resolver');118 var dir = path.join(resolverDir, 'bar');119 var otherDir = path.join(resolverDir, 'other_path');120 t.equal(121 resolve.sync('root', {122 basedir: dir,123 paths: [otherDir]124 }),125 path.join(resolverDir, 'other_path/root.js')126 );127 t.equal(128 resolve.sync('lib/other-lib', {129 basedir: dir,130 paths: [otherDir]131 }),132 path.join(resolverDir, 'other_path/lib/other-lib.js')133 );134 t.throws(function () {135 resolve.sync('root', { basedir: dir });136 });137 t.throws(function () {138 resolve.sync('zzz', {139 basedir: dir,140 paths: [otherDir]141 });142 });143 t.end();144});145test('path iterator', function (t) {146 var resolverDir = path.join(__dirname, 'resolver');147 var exactIterator = function (x, start, getPackageCandidates, opts) {148 return [path.join(resolverDir, x)];149 };150 t.equal(151 resolve.sync('baz', { packageIterator: exactIterator }),152 path.join(resolverDir, 'baz/quux.js')153 );154 t.end();155});156test('incorrect main', function (t) {157 var resolverDir = path.join(__dirname, 'resolver');158 var dir = path.join(resolverDir, 'incorrect_main');159 t.equal(160 resolve.sync('./incorrect_main', { basedir: resolverDir }),161 path.join(dir, 'index.js')162 );163 t.end();164});165var stubStatSync = function stubStatSync(fn) {166 var fs = require('fs');167 var statSync = fs.statSync;168 try {169 fs.statSync = function () {170 throw new EvalError('Unknown Error');171 };172 return fn();173 } finally {174 fs.statSync = statSync;175 }176};177test('#79 - re-throw non ENOENT errors from stat', function (t) {178 var dir = path.join(__dirname, 'resolver');179 stubStatSync(function () {180 t.throws(function () {181 resolve.sync('foo', { basedir: dir });182 }, /Unknown Error/);183 });184 t.end();185});186test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {187 var dir = path.join(__dirname, 'resolver');188 t.equal(189 resolve.sync('./foo', { basedir: path.join(dir, 'same_names') }),190 path.join(dir, 'same_names/foo.js')191 );192 t.equal(193 resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }),194 path.join(dir, 'same_names/foo/index.js')195 );196 t.end();197});198test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) {199 var dir = path.join(__dirname, 'resolver');200 t.equal(201 resolve.sync('./', { basedir: path.join(dir, 'same_names/foo') }),202 path.join(dir, 'same_names/foo/index.js')203 );204 t.equal(205 resolve.sync('.', { basedir: path.join(dir, 'same_names/foo') }),206 path.join(dir, 'same_names/foo/index.js')207 );208 t.end();209});210test('sync: #121 - treating an existing file as a dir when no basedir', function (t) {211 var testFile = path.basename(__filename);212 t.test('sanity check', function (st) {213 st.equal(214 resolve.sync('./' + testFile),215 __filename,216 'sanity check'217 );218 st.end();219 });220 t.test('with a fake directory', function (st) {221 function run() { return resolve.sync('./' + testFile + '/blah'); }222 st.throws(run, 'throws an error');223 try {224 run();225 } catch (e) {226 st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');227 st.equal(228 e.message,229 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',230 'can not find nonexistent module'231 );232 }233 st.end();234 });235 t.end();236});237test('sync dot main', function (t) {238 var start = new Date();239 t.equal(resolve.sync('./resolver/dot_main'), path.join(__dirname, 'resolver/dot_main/index.js'));240 t.ok(new Date() - start < 50, 'resolve.sync timedout');241 t.end();242});243test('sync dot slash main', function (t) {244 var start = new Date();245 t.equal(resolve.sync('./resolver/dot_slash_main'), path.join(__dirname, 'resolver/dot_slash_main/index.js'));246 t.ok(new Date() - start < 50, 'resolve.sync timedout');247 t.end();248});249test('not a directory', function (t) {250 var path = './foo';251 try {252 resolve.sync(path, { basedir: __filename });253 t.fail();254 } catch (err) {255 t.ok(err, 'a non-directory errors');256 t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'");257 t.equal(err && err.code, 'MODULE_NOT_FOUND');258 }259 t.end();260});261test('non-string "main" field in package.json', function (t) {262 var dir = path.join(__dirname, 'resolver');263 try {264 var result = resolve.sync('./invalid_main', { basedir: dir });265 t.equal(result, undefined, 'result should not exist');266 t.fail('should not get here');267 } catch (err) {268 t.ok(err, 'errors on non-string main');269 t.equal(err.message, 'package âinvalid mainâ `main` must be a string');270 t.equal(err.code, 'INVALID_PACKAGE_MAIN');271 }272 t.end();273});274test('non-string "main" field in package.json', function (t) {275 var dir = path.join(__dirname, 'resolver');276 try {277 var result = resolve.sync('./invalid_main', { basedir: dir });278 t.equal(result, undefined, 'result should not exist');279 t.fail('should not get here');280 } catch (err) {281 t.ok(err, 'errors on non-string main');282 t.equal(err.message, 'package âinvalid mainâ `main` must be a string');283 t.equal(err.code, 'INVALID_PACKAGE_MAIN');284 }285 t.end();286});287test('browser field in package.json', function (t) {288 var dir = path.join(__dirname, 'resolver');289 var res = resolve.sync('./browser_field', {290 basedir: dir,291 packageFilter: function packageFilter(pkg) {292 if (pkg.browser) {293 pkg.main = pkg.browser; // eslint-disable-line no-param-reassign294 delete pkg.browser; // eslint-disable-line no-param-reassign295 }296 return pkg;297 }298 });299 t.equal(res, path.join(dir, 'browser_field', 'b.js'));300 t.end();...
build.js
Source: build.js
...6const gutil = require('gulp-util');7const utils = require('./build-utils.js');8gulp.task('partials', function () {9 return gulp.src([10 path.join(conf.paths.src, '/app/**/*.html'),11 path.join(conf.paths.tmp, '/serve/app/**/*.html'),12 ])13 .pipe($.minifyHtml({14 empty: true,15 spare: true,16 quotes: true,17 }))18 .pipe($.angularTemplatecache('templateCacheHtml.js', {19 module: 'aarp-staying-sharp',20 root: 'app',21 }))22 .pipe(gulp.dest(conf.paths.tmp + '/partials/'));23});24gulp.task('partials:symlink', ['partials'], function () {25 return gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'))26 .pipe($.symlink([27 path.join(conf.paths.tmp, '/serve/templateCacheHtml.js'),28 ], { force: true }));29});30gulp.task('partials:watch', ['partials:symlink'], function () {31 gulp.watch(path.join(conf.paths.src, '/app/**/*.html'), ['partials']);32});33gulp.task('html', ['inject', 'partials'], function () {34 const htmlFilter = $.filter('*.html', { restore: true });35 const jsFilter = $.filter('**/*.js', { restore: true });36 const cssFilter = $.filter('**/*.css', { restore: true });37 const assets = $.useref.assets();38 return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))39 .pipe(assets)40 .pipe($.rev())41 .pipe(jsFilter)42 .pipe($.uglify({ preserveComments: $.uglifySaveLicense }))43 .on('error', conf.errorHandler('Uglify'))44 .pipe(jsFilter.restore)45 .pipe(cssFilter)46 .pipe($.csso())47 .pipe(cssFilter.restore)48 .pipe(assets.restore())49 .pipe($.useref())50 .pipe($.revReplace())51 .pipe(htmlFilter)52 .pipe($.minifyHtml({53 empty: true,54 spare: true,55 quotes: true,56 conditionals: true,57 }))58 .pipe(htmlFilter.restore)59 .pipe(gulp.dest(path.join(conf.paths.dist, '/')))60 .pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true }));61});62// Only applies for fonts from bower dependencies63// Custom fonts are handled by the "other" task64gulp.task('fonts', function () {65 return gulp.src($.mainBowerFiles())66 .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}'))67 .pipe($.flatten())68 .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));69});70gulp.task('server', function () {71 return gulp.src([72 path.join(conf.paths.src, '/server.js'),73 path.join(conf.paths.src, '/package.json')74 ])75 .pipe(gulp.dest(path.join(conf.paths.dist, '/')));76});77gulp.task('lib', function () {78 return gulp.src([79 path.join(conf.paths.src, '/lib/**/*.js')80 ]).pipe(gulp.dest(path.join(conf.paths.dist, '/lib/')));81});82gulp.task('robots', function () {83 const robotsFiles = {84 dev: 'robots.disallow.txt',85 staging: 'robots.disallow.txt',86 production: 'robots.production.txt',87 };88 const robotsForEnv = robotsFiles[utils.getEnvName()];89 return gulp.src([90 path.join(conf.paths.src, robotsForEnv)91 ])92 .pipe(rename('robots.txt'))93 .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve')))94 .pipe(gulp.dest(path.join(conf.paths.dist, '/')))95});96gulp.task('other', function () {97 return gulp.src([98 path.join(conf.paths.src, '/**/*'),99 path.join('!' + conf.paths.src, '/robots.*'),100 path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}'),101 path.join(conf.paths.src, '/**/*'),102 ])103 .pipe($.filter((file) => file.stat.isFile()))104 .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/')))105 .pipe(gulp.dest(path.join(conf.paths.dist, '/')));106});107gulp.task('elasticBeanstalkConfig', function () {108 return gulp.src([109 path.join(conf.paths.src, '/.elasticbeanstalk/**/*')110 ]).pipe(gulp.dest(path.join(conf.paths.dist, '/.elasticbeanstalk/')));111});112gulp.task('other:watch', ['other'], function () {113 gulp.watch([114 path.join(conf.paths.src, '/**/*'),115 path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}'),116 ], ['other']);117});118gulp.task('verificationFile', function () {119 const verificationFiles = {120 dev: '/client/verification-files/googlebebc04c0a7a96d72.html',121 };122 const filePath = verificationFiles[utils.getEnvName()];123 if (!filePath) { return; }124 return gulp.src(125 path.join(conf.paths.root, filePath)126 ).pipe(gulp.dest(path.join(conf.paths.dist, '/')));127});128gulp.task('clean', function (done) {129 gutil.log('deleting dist and tmp files...');130 $.del([131 path.join(conf.paths.dist, '/'),132 path.join(conf.paths.tmp, '/'),133 ], { force: true }, done);134});135gulp.task(136 'build',137 [138 'html',139 'fonts',140 'server',141 'lib',142 'redirects:import',143 'verificationFile',144 'robots',145 'other',146 'elasticBeanstalkConfig'...
constants.js
Source: constants.js
1var path = require('path');2var pkg = require('../../package.json');3var pathToRoot = path.join(__dirname, '../../');4var pathToSrc = path.join(pathToRoot, 'src/');5var pathToLib = path.join(pathToRoot, 'lib/');6var pathToImageTest = path.join(pathToRoot, 'test/image');7var pathToDist = path.join(pathToRoot, 'dist/');8var pathToBuild = path.join(pathToRoot, 'build/');9var pathToTopojsonSrc = path.join(10 path.dirname(require.resolve('sane-topojson')), 'dist/'11);12var partialBundleNames = [13 'basic', 'cartesian', 'geo', 'gl3d', 'gl2d', 'mapbox'14];15var partialBundlePaths = partialBundleNames.map(function(name) {16 return {17 name: name,18 index: path.join(pathToLib, 'index-' + name + '.js'),19 dist: path.join(pathToDist, 'plotly-' + name + '.js'),20 distMin: path.join(pathToDist, 'plotly-' + name + '.min.js')21 };22});23var year = (new Date()).getFullYear();24module.exports = {25 pathToRoot: pathToRoot,26 pathToSrc: pathToSrc,27 pathToLib: pathToLib,28 pathToBuild: pathToBuild,29 pathToDist: pathToDist,30 pathToPlotlyIndex: path.join(pathToLib, 'index.js'),31 pathToPlotlyCore: path.join(pathToSrc, 'core.js'),32 pathToPlotlyBuild: path.join(pathToBuild, 'plotly.js'),33 pathToPlotlyDist: path.join(pathToDist, 'plotly.js'),34 pathToPlotlyDistMin: path.join(pathToDist, 'plotly.min.js'),35 pathToPlotlyDistWithMeta: path.join(pathToDist, 'plotly-with-meta.js'),36 partialBundleNames: partialBundleNames,37 partialBundlePaths: partialBundlePaths,38 pathToTopojsonSrc: pathToTopojsonSrc,39 pathToTopojsonDist: path.join(pathToDist, 'topojson/'),40 pathToPlotlyGeoAssetsSrc: path.join(pathToSrc, 'assets/geo_assets.js'),41 pathToPlotlyGeoAssetsDist: path.join(pathToDist, 'plotly-geo-assets.js'),42 pathToFontSVG: path.join(pathToSrc, 'fonts/ploticon/ploticon.svg'),43 pathToFontSVGBuild: path.join(pathToBuild, 'ploticon.js'),44 pathToSCSS: path.join(pathToSrc, 'css/style.scss'),45 pathToCSSBuild: path.join(pathToBuild, 'plotcss.js'),46 pathToTestDashboardBundle: path.join(pathToBuild, 'test_dashboard-bundle.js'),47 pathToImageViewerBundle: path.join(pathToBuild, 'image_viewer-bundle.js'),48 pathToTestImageMocks: path.join(pathToImageTest, 'mocks/'),49 pathToTestImageBaselines: path.join(pathToImageTest, 'baselines/'),50 pathToTestImages: path.join(pathToBuild, 'test_images/'),51 pathToTestImagesDiff: path.join(pathToBuild, 'test_images_diff/'),52 pathToTestImagesDiffList: path.join(pathToBuild, 'list_of_incorrect_images.txt'),53 pathToJasmineTests: path.join(pathToRoot, 'test/jasmine/tests'),54 pathToJasmineBundleTests: path.join(pathToRoot, 'test/jasmine/bundle_tests'),55 pathToRequireJS: path.join(pathToRoot, 'node_modules', 'requirejs', 'require.js'),56 pathToRequireJSFixture: path.join(pathToBuild, 'requirejs_fixture.js'),57 // this mapbox access token is 'public', no need to hide it58 // more info: https://www.mapbox.com/help/define-access-token/59 mapboxAccessToken: 'pk.eyJ1IjoiZXRwaW5hcmQiLCJhIjoiY2luMHIzdHE0MGFxNXVubTRxczZ2YmUxaCJ9.hwWZful0U2CQxit4ItNsiQ',60 pathToCredentials: path.join(pathToBuild, 'credentials.json'),61 pathToSetPlotConfig: path.join(pathToBuild, 'set_plot_config.js'),62 testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'imagetest',63 testContainerPort: '9010',64 testContainerUrl: 'http://localhost:9010/',65 testContainerHome: '/var/www/streambed/image_server/plotly.js',66 uglifyOptions: {67 fromString: true,68 mangle: true,69 compress: {70 warnings: false,71 screw_ie8: true72 },73 output: {74 beautify: false,75 ascii_only: true76 }77 },78 licenseDist: [79 '/**',80 '* plotly.js v' + pkg.version,81 '* Copyright 2012-' + year + ', Plotly, Inc.',82 '* All rights reserved.',83 '* Licensed under the MIT license',84 '*/'85 ].join('\n'),86 licenseSrc: [87 '/**',88 '* Copyright 2012-' + year + ', Plotly, Inc.',89 '* All rights reserved.',90 '*',91 '* This source code is licensed under the MIT license found in the',92 '* LICENSE file in the root directory of this source tree.',93 '*/'94 ].join('\n')...
App.js
Source: App.js
...6 },7 execute: function(args) {8 var path = require('path'),9 cwd = process.cwd(),10 sdkVersionFile = path.join(cwd, 'version.txt'),11 sdkVersion = new Ext.Version(require('fs').readFileSync(sdkVersionFile, 'utf8').trim()),12 appPath = path.resolve(args.path);13 this.mkdir(14 appPath,15 path.join(appPath, 'app'),16 path.join(appPath, 'app', 'model'),17 path.join(appPath, 'app', 'view'),18 path.join(appPath, 'app', 'controller'),19 path.join(appPath, 'app', 'store'),20 path.join(appPath, 'app', 'profile'),21 path.join(appPath, 'sdk'),22 path.join(appPath, 'sdk', 'src'),23 path.join(appPath, 'sdk', 'resources'),24 path.join(appPath, 'resources'),25 path.join(appPath, 'resources', 'css'),26 path.join(appPath, 'resources', 'images'),27 path.join(appPath, 'resources', 'icons'),28 path.join(appPath, 'resources', 'sass')29 );30 this.template('.senchasdk', path.join(appPath, '.senchasdk'));31 this.template('index.html', path.join(appPath, 'index.html'));32 this.template('app.js', path.join(appPath, 'app.js'));33 this.template('packager.json', path.join(appPath, 'packager.json'));34 this.template('app.json', path.join(appPath, 'app.json'), {35 name: args.name,36 sdkShortVersion: sdkVersion.getShortVersion(),37 sdkVersion: sdkVersion.toString(),38 library: args.library,39 uniqueId: this.getUniqueId()40 });41 this.template('app/view/Main.js', path.join(appPath, 'app', 'view', 'Main.js'));42 this.directory(path.join(cwd, 'src'), path.join(appPath, 'sdk', 'src'));43 this.directory(path.join(cwd, 'resources'), path.join(appPath, 'sdk', 'resources'));44 this.directory(path.join(cwd, 'command', 'src', 'module', 'generate', 'App', 'resources', 'icons'), path.join(appPath, 'resources', 'icons'));45 this.directory(path.join(cwd, 'command', 'src', 'module', 'generate', 'App', 'resources', 'loading'), path.join(appPath, 'resources', 'loading'));46 this.directory(path.join(cwd, 'command', 'src', 'module', 'generate', 'App', 'resources', 'startup'), path.join(appPath, 'resources', 'startup'));47 this.directory(path.join(cwd, 'command'), path.join(appPath, 'sdk', 'command'));48 this.file(path.join(cwd, 'microloader/development.js'), path.join(appPath, 'sdk', 'microloader/development.js'));49 this.file(path.join(cwd, 'microloader/testing.js'), path.join(appPath, 'sdk', 'microloader/testing.js'));50 this.file(path.join(cwd, 'microloader/production.js'), path.join(appPath, 'sdk', 'microloader/production.js'));51 this.file(path.join(cwd, 'version.txt'), path.join(appPath, 'sdk', 'version.txt'));52 this.file(path.join(cwd, 'sencha-touch-debug.js'), path.join(appPath, 'sdk', 'sencha-touch.js'));53 this.file(path.join(cwd, 'sencha-touch-all-debug.js'), path.join(appPath, 'sdk', 'sencha-touch-all.js'));54 this.template('resources/sass/app.scss', path.join(appPath, 'resources' , 'sass', 'app.scss'));55 this.template('resources/sass/config.rb', path.join(appPath, 'resources' , 'sass', 'config.rb'));56 this.file(path.join(cwd, 'resources/css-debug/sencha-touch.css'), path.join(appPath, 'resources', 'css', 'app.css'));57 }...
code.spec.js
Source: code.spec.js
1const joinPath = require('./code');2describe('Tests', () => {3 test('the tests', () => {4 expect(joinPath('portion1', 'portion2')).toEqual('portion1/portion2');5 expect(joinPath('portion1/', 'portion2')).toEqual('portion1/portion2');6 expect(joinPath('portion1', '/portion2')).toEqual('portion1/portion2');7 expect(joinPath('portion1/', '/portion2')).toEqual('portion1/portion2');8 expect(joinPath('5wf7fny', 'stJKXlc8')).toEqual('5wf7fny/stJKXlc8');9 expect(joinPath('5wf7fny/', 'stJKXlc8')).toEqual('5wf7fny/stJKXlc8');10 expect(joinPath('5wf7fny', '/stJKXlc8')).toEqual('5wf7fny/stJKXlc8');11 expect(joinPath('5wf7fny/', '/stJKXlc8')).toEqual('5wf7fny/stJKXlc8');12 expect(joinPath('FKBZOBHo', 'GNcYGnB')).toEqual('FKBZOBHo/GNcYGnB');13 expect(joinPath('FKBZOBHo/', 'GNcYGnB')).toEqual('FKBZOBHo/GNcYGnB');14 expect(joinPath('FKBZOBHo', '/GNcYGnB')).toEqual('FKBZOBHo/GNcYGnB');15 expect(joinPath('FKBZOBHo/', '/GNcYGnB')).toEqual('FKBZOBHo/GNcYGnB');16 expect(joinPath('vL533Y3', 'uVz3nul')).toEqual('vL533Y3/uVz3nul');17 expect(joinPath('vL533Y3/', 'uVz3nul')).toEqual('vL533Y3/uVz3nul');18 expect(joinPath('vL533Y3', '/uVz3nul')).toEqual('vL533Y3/uVz3nul');19 expect(joinPath('vL533Y3/', '/uVz3nul')).toEqual('vL533Y3/uVz3nul');20 expect(joinPath('kfDOTwf', 'Xr8viY8e')).toEqual('kfDOTwf/Xr8viY8e');21 expect(joinPath('kfDOTwf/', 'Xr8viY8e')).toEqual('kfDOTwf/Xr8viY8e');22 expect(joinPath('kfDOTwf', '/Xr8viY8e')).toEqual('kfDOTwf/Xr8viY8e');23 expect(joinPath('kfDOTwf/', '/Xr8viY8e')).toEqual('kfDOTwf/Xr8viY8e');24 expect(joinPath('F4tBPmoV', 'Lv18joOw')).toEqual('F4tBPmoV/Lv18joOw');25 expect(joinPath('F4tBPmoV/', 'Lv18joOw')).toEqual('F4tBPmoV/Lv18joOw');26 expect(joinPath('F4tBPmoV', '/Lv18joOw')).toEqual('F4tBPmoV/Lv18joOw');27 expect(joinPath('F4tBPmoV/', '/Lv18joOw')).toEqual('F4tBPmoV/Lv18joOw');28 expect(joinPath('7ASOjVuT', 'wwPOgKX')).toEqual('7ASOjVuT/wwPOgKX');29 expect(joinPath('7ASOjVuT/', 'wwPOgKX')).toEqual('7ASOjVuT/wwPOgKX');30 expect(joinPath('7ASOjVuT', '/wwPOgKX')).toEqual('7ASOjVuT/wwPOgKX');31 expect(joinPath('7ASOjVuT/', '/wwPOgKX')).toEqual('7ASOjVuT/wwPOgKX');32 expect(joinPath('r1AiTrL', 'KkyjD3K')).toEqual('r1AiTrL/KkyjD3K');33 expect(joinPath('r1AiTrL/', 'KkyjD3K')).toEqual('r1AiTrL/KkyjD3K');34 expect(joinPath('r1AiTrL', '/KkyjD3K')).toEqual('r1AiTrL/KkyjD3K');35 expect(joinPath('r1AiTrL/', '/KkyjD3K')).toEqual('r1AiTrL/KkyjD3K');36 expect(joinPath('1h1gRAxu', 'apQtQYgl')).toEqual('1h1gRAxu/apQtQYgl');37 expect(joinPath('1h1gRAxu/', 'apQtQYgl')).toEqual('1h1gRAxu/apQtQYgl');38 expect(joinPath('1h1gRAxu', '/apQtQYgl')).toEqual('1h1gRAxu/apQtQYgl');39 expect(joinPath('1h1gRAxu/', '/apQtQYgl')).toEqual('1h1gRAxu/apQtQYgl');40 expect(joinPath('IYo5kuL', 'QFEM6dSv')).toEqual('IYo5kuL/QFEM6dSv');41 expect(joinPath('IYo5kuL/', 'QFEM6dSv')).toEqual('IYo5kuL/QFEM6dSv');42 expect(joinPath('IYo5kuL', '/QFEM6dSv')).toEqual('IYo5kuL/QFEM6dSv');43 expect(joinPath('IYo5kuL/', '/QFEM6dSv')).toEqual('IYo5kuL/QFEM6dSv');44 expect(joinPath('M6c7OnQI', 'nj-CEAqV')).toEqual('M6c7OnQI/nj-CEAqV');45 expect(joinPath('M6c7OnQI/', 'nj-CEAqV')).toEqual('M6c7OnQI/nj-CEAqV');46 expect(joinPath('M6c7OnQI', '/nj-CEAqV')).toEqual('M6c7OnQI/nj-CEAqV');47 expect(joinPath('M6c7OnQI/', '/nj-CEAqV')).toEqual('M6c7OnQI/nj-CEAqV');48 });...
string.test.js
Source: string.test.js
2import { toHumanCase } from './string';3import { toCamelCase } from './string';4import { transformString } from './string';5test('split', () => {6 expect(split('Test String').join(' ')).toBe('test string');7 expect(split('Test String A').join(' ')).toBe('test string a');8 expect(split('Test StringA').join(' ')).toBe('test string a');9 expect(split('Test String 1').join(' ')).toBe('test string 1');10 expect(split('Test String1').join(' ')).toBe('test string 1');11 expect(split('test string').join(' ')).toBe('test string');12 expect(split('tEst string').join(' ')).toBe('t est string');13 expect(split('tEst stRing').join(' ')).toBe('t est st ring');14 expect(split('test-string').join(' ')).toBe('test string');15 expect(split('test_string').join(' ')).toBe('test string');16 expect(split('test-string-123').join(' ')).toBe('test string 123');17 expect(split('test_string_123').join(' ')).toBe('test string 123');18 expect(split('test+string+123').join(' ')).toBe('test string 123');19 expect(split('test-string123').join(' ')).toBe('test string 123');20 expect(split('test_string123').join(' ')).toBe('test string 123');21 expect(split('testString123').join(' ')).toBe('test string 123');22 expect(split('test123String').join(' ')).toBe('test 123 string');23 expect(split('Test123string').join(' ')).toBe('test 123 string');24 expect(split('test string 123').join(' ')).toBe('test string 123');25 expect(split('testAString').join(' ')).toBe('test a string');26 expect(split('ABCString').join(' ')).toBe('a b c string');27});28test('to human case', () => {29 expect(toHumanCase('testString')).toBe('Test String');30});31test('to camel case', () => {32 expect(toCamelCase('Test String')).toBe('testString');33});34test('transform string', () => {35 expect(36 transformString('translate', 100, '50%', 'rotate', 45, 'scaleX', '2.0')37 ).toBe('translate(100, 50%) rotate(45) scaleX(2.0)');...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: `example-${page.viewportSize().width}x${page.viewportSize().height}.png` });7 await browser.close();8})();9const path = require('path');10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.screenshot({ path: path.join(__dirname, `example-${page.viewportSize().width}x${page.viewportSize().height}.png`) });16 await browser.close();17})();18const path = require('path');19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.screenshot({ path: path.join(__dirname, `example-${page.viewportSize().width}x${page.viewportSize().height}.png`) });25 await browser.close();26})();27const path = require('path');28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 await page.screenshot({ path: path.join(__dirname, `example-${page.viewportSize().width}x${page.viewportSize().height}.png`) });34 await browser.close();35})();36const path = require('path');37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.screenshot({ path: path.join(__dirname, `example
Using AI Code Generation
1const path = require('path');2const { join } = require('path');3const fs = require('fs');4const { chromium } = require('playwright');5(async () => {6 const browser = await chromium.launch();7 const page = await browser.newPage();8 await page.screenshot({ path: join(path.resolve(), 'google.png') });9 await browser.close();10})();11const path = require('path');12const { join } = require('path');13const fs = require('fs');14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const page = await browser.newPage();18 await page.screenshot({ path: join(path.resolve(), 'google.png') });19 await browser.close();20})();21const path = require('path');22const { join } = require('path');23const fs = require('fs');24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const page = await browser.newPage();28 await page.screenshot({ path: join(path.resolve(), 'google.png') });29 await browser.close();30})();31const path = require('path');32const { join } = require('path');33const fs = require('fs');34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const page = await browser.newPage();38 await page.screenshot({ path: join(path.resolve(), 'google.png') });39 await browser.close();40})();41const path = require('path');42const { join } = require('path');43const fs = require('fs');44const { chromium } = require('playwright');45(async () => {46 const browser = await chromium.launch();47 const page = await browser.newPage();48 await page.screenshot({ path: join(path.resolve(), 'google.png') });
Using AI Code Generation
1const { join } = require('@playwright/test');2const path = join(__dirname, 'test.js');3const path = require('path');4const path = path.join(__dirname, 'test.js');5const path = require('path');6const path = path.resolve(__dirname, 'test.js');7const path = require('path');8const path = path.normalize(__dirname + '/test.js');9const path = require('path');10const path = path.format({11});12const path = require('path');13const path = path.parse(__dirname + '/test.js');14path.base = 'test.js';15path = path.format(path);16const path = require('path');17const path = path.posix.join(__dirname, 'test.js');18const path = require('path');19const path = path.win32.join(__dirname, 'test.js');20const path = require('path');21const path = path.posix.resolve(__dirname, 'test.js');22const path = require('path');23const path = path.win32.resolve(__dirname, 'test.js');24const path = require('path');25const path = path.posix.normalize(__dirname + '/test.js');26const path = require('path');27const path = path.win32.normalize(__dirname + '/test.js');28const path = require('path');29const path = path.posix.format({30});31const path = require('path');32const path = path.win32.format({33});34const path = require('path');35const path = path.posix.parse(__dirname + '/test.js');36path.base = 'test.js';37path = path.posix.format(path
Using AI Code Generation
1const {join} = require('@playwright/test');2const {test} = require('@playwright/test');3test('test', async ({page}) => {4 await page.goto(join(__dirname, 'index.html'));5});6const {join} = require('path');7const {test} = require('@playwright/test');8test('test', async ({page}) => {9 await page.goto(join(__dirname, 'index.html'));10});
Using AI Code Generation
1const { join } = require('path');2const pathToExtension = join(__dirname, 'extension');3const browser = await chromium.launch({4 `--disable-extensions-except=${pathToExtension}`,5 `--load-extension=${pathToExtension}`,6});7const context = await browser.newContext();8const page = await context.newPage();9await browser.close();10const { launchPersistentContext } = require('playwright');11const pathToExtension = join(__dirname, 'extension');12const context = await launchPersistentContext(pathToExtension, {13 `--disable-extensions-except=${pathToExtension}`,14 `--load-extension=${pathToExtension}`,15});16const page = await context.newPage();17await browser.close();
Using AI Code Generation
1const { test } = require('@playwright/test');2test('Test Runner join method', async ({ page }) => {3 const title = page.locator('text=Get started');4 await title.click();5 await page.waitForNavigation();6 const heading = page.locator('text=Installation');7 await heading.click();8 await page.waitForNavigation();9 const url = page.url();10 console.log(url);11 const path = test.fixtures.join(url);12 console.log(path);13});
Using AI Code Generation
1const { join } = require('@playwright/test');2const path = join(__dirname, 'folder1', 'folder2', 'folder3');3console.log(path);4const path = require('path');5const joinPath = path.join(__dirname, 'folder1', 'folder2', 'folder3');6console.log(joinPath);7const { join } = require('@playwright/test');8const path = join(__dirname, 'folder1', 'folder2', 'folder3');9console.log(path);10const path = require('path');11const joinPath = path.join(__dirname, 'folder1', 'folder2', 'folder3');12console.log(joinPath);13const { join } = require('@playwright/test');14const path = join(__dirname, 'folder1', 'folder2', 'folder3');15console.log(path);16const path = require('path');17const joinPath = path.join(__dirname, 'folder1', 'folder2', 'folder3');18console.log(joinPath);
Using AI Code Generation
1const { join } = require('@playwright/test');2const path = join(__dirname, 'test.js');3console.log(path);4const path = require('path');5const path = path.join(__dirname, 'test.js');6console.log(path);7const path = require('path');8const path = path.join(__dirname, 'test.js');9console.log(path);10const { join } = require('@playwright/test');11const path = join(__dirname, 'test.js');12console.log(path);13const path = require('path');14const path = path.join(__dirname, 'test.js');15console.log(path);16const path = require('path');17const path = path.join(__dirname, 'test.js');18console.log(path);19const { join } = require('@playwright/test');20const path = join(__dirname, 'test.js');21console.log(path);22const path = require('path');23const path = path.join(__dirname, 'test.js');24console.log(path);25const path = require('path');26const path = path.join(__dirname, 'test.js');27console.log(path);28const { join } = require('@playwright/test');29const path = join(__dirname, 'test.js');30console.log(path);31const path = require('path');
Using AI Code Generation
1const { join } = require('path');2const path = join(__dirname, 'screenshot.png');3console.log(path);4const { join } = require('path');5const path = join(__dirname, 'screenshot.png');6console.log(path);7const path = require('path').join(__dirname, 'screenshot.png');8console.log(path);9const path = require('path').join(__dirname, 'screenshot.png');10console.log(path);11const path = require('path').join(__dirname, 'screenshot.png');12console.log(path);13const path = require('path').join(__dirname, 'screenshot.png');14console.log(path);15const path = require('path').join(__dirname, 'screenshot.png');16console.log(path);17const path = require('path').join(__dirname, 'screenshot.png');18console.log(path);19const path = require('path').join(__dirname, 'screenshot.png');20console.log(path);21const path = require('path').join(__dirname, 'screenshot.png');22console.log(path);23const path = require('path').join(__dirname, 'screenshot.png');24console.log(path);
Jest + Playwright - Test callbacks of event-based DOM library
firefox browser does not start in playwright
Is it possible to get the selector from a locator object in playwright?
How to run a list of test suites in a single file concurrently in jest?
Running Playwright in Azure Function
firefox browser does not start in playwright
This question is quite close to a "need more focus" question. But let's try to give it some focus:
Does Playwright has access to the cPicker object on the page? Does it has access to the window object?
Yes, you can access both cPicker and the window object inside an evaluate call.
Should I trigger the events from the HTML file itself, and in the callbacks, print in the DOM the result, in some dummy-element, and then infer from that dummy element text that the callbacks fired?
Exactly, or you can assign values to a javascript variable:
const cPicker = new ColorPicker({
onClickOutside(e){
},
onInput(color){
window['color'] = color;
},
onChange(color){
window['result'] = color;
}
})
And then
it('Should call all callbacks with correct arguments', async() => {
await page.goto(`http://localhost:5000/tests/visual/basic.html`, {waitUntil:'load'})
// Wait until the next frame
await page.evaluate(() => new Promise(requestAnimationFrame))
// Act
// Assert
const result = await page.evaluate(() => window['color']);
// Check the value
})
Check out the latest blogs from LambdaTest on this topic:
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!