Best Python code snippet using autotest_python
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'...
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!!