Best JavaScript code snippet using jest
fvs.spec.js
Source:fvs.spec.js
...22 let hash;23 beforeEach(function () {24 fs.mkdirSync('.fvs');25 fs.mkdirSync('.fvs/objects');26 hash = getSha1('test content');27 });28 it('returns a hash of the filecontents', function () {29 let result = fvs.createFVSObject('test content');30 expect(result).to.be.equal(hash);31 });32 it('creates a directory with the first two characters as the directory name', function () {33 fvs.createFVSObject('test content');34 expect(fs.statSync('./.fvs/objects/' + hash.slice(0, 2))).to.exist;35 });36 it('creates a file with the remaining characters of the hash', function () {37 fvs.createFVSObject('test content');38 expect(fs.readFileSync('./.fvs/objects/' + hash.slice(0, 2) + '/' + hash.slice(2))).to.not.throw;39 });40 it('does not create a new object when one exists', function () {41 fvs.createFVSObject('test content');42 expect(fvs.createFVSObject('test content')).to.not.throw;43 });44 });45 describe('createBlobObject', function () {46 let hash;47 beforeEach(function () {48 fs.mkdirSync('.fvs');49 fs.mkdirSync('.fvs/objects');50 fs.writeFileSync('./test1.txt', 'test1 content', 'utf8');51 hash = getSha1('test1 content');52 });53 afterEach(function () { rmdir('test1.txt'); });54 it('returns a hash of the filecontents of the given file', function () {55 let result = fvs.createBlobObject('test1.txt');56 expect(result).to.be.equal(hash);57 });58 it('does not create a new object when one exists', function () {59 fvs.createBlobObject('test1.txt');60 expect(fvs.createBlobObject('test1.txt')).to.not.throw;61 });62 });63 describe('updateIndex', function () {64 let hash,65 fileName,66 index;67 beforeEach(function () {68 fs.mkdirSync('.fvs');69 fs.mkdirSync('.fvs/objects');70 fs.writeFileSync('./test1.txt', 'test1 content', 'utf8');71 fs.writeFileSync('./.fvs/index', '', 'utf8');72 fileName = 'test1.txt';73 hash = getSha1('test1 content');74 index = 'test1.txt' + ' ' + hash;75 });76 afterEach(function () { rmdir('test1.txt'); });77 it('creates a new entry in the index', function () {78 fvs.updateIndex(index, fileName, hash);79 expect(fs.readFileSync('./.fvs/index', 'utf8')).to.be.equal(index);80 });81 it('updates an existing entry in the index', function () {82 fvs.updateIndex(index, fileName, hash);83 fs.writeFileSync('test1.txt', 'test1 edited content', 'utf8');84 hash = getSha1('test1 edited content');85 let newIndex = fvs.updateIndex(index, fileName, hash);86 expect(fs.readFileSync('./.fvs/index', 'utf8')).to.be.equal(newIndex);87 });88 });89 });90 describe('commands', function () {91 describe('accepts "init" as a command', function () {92 let rootDir,93 fvsDir,94 refs,95 headContent;96 it('creates the appropriate directories and files', function () {97 fvs.init();98 rootDir = fs.readdirSync('./');99 fvsDir = fs.readdirSync('./.fvs');100 refs = fs.readdirSync('./.fvs/refs');101 headContent = fs.readFileSync('.fvs/HEAD', 'utf8');102 expect(rootDir.indexOf('.fvs') !== -1).to.be.true;103 expect(fvsDir.indexOf('objects') !== -1).to.be.true;104 expect(fvsDir.indexOf('HEAD') !== -1).to.be.true;105 expect(fvsDir.indexOf('refs') !== -1).to.be.true;106 expect(refs.indexOf('master') !== -1).to.be.true;107 expect(headContent).to.be.equal('refs/master');108 });109 it('throws an error if an fvs directory already exists', function () {110 fs.mkdirSync('.fvs');111 expect(fvs.init).to.throw('.fvs already exists');112 });113 });114 describe ('accepts "add" as a command', function () {115 let blobHash,116 blobDir,117 blobFile;118 beforeEach(function () {119 fs.mkdirSync('.fvs');120 fs.mkdirSync('.fvs/objects');121 fs.writeFileSync('./test1.txt', 'test1 content', 'utf8');122 blobHash = getSha1('test1 content');123 blobDir = blobHash.slice(0, 2);124 blobFile = blobHash.slice(2);125 });126 afterEach(function () { rmdir('test1.txt'); });127 it('throws an error if a filename is not specified', function () {128 process.argv = ['', 'fvs', 'add'];129 expect(fvs.add).to.throw('No filename specified');130 });131 it('creates a blob object that contains the content of test1.txt', function () {132 process.argv = ['', 'fvs', 'add', 'test1.txt'];133 fvs.add();134 let file = fs.readFileSync('./.fvs/objects/' + blobDir + '/' + blobFile, 'utf8');135 expect(file).to.be.equal('test1 content');136 });137 it('adds an index entry that points at the blob', function () {138 process.argv = ['', 'fvs', 'add', 'test1.txt'];139 fvs.add();140 let index = fs.readFileSync('./.fvs/index', 'utf8');141 expect(index).to.be.equal('test1.txt' + ' ' + blobHash);142 });143 it('updates the index entry after making a correction', function () {144 fs.writeFileSync('./test1.txt', 'test1 content edited', 'utf8');145 blobHash = getSha1('test1 content edited');146 blobDir = blobHash.slice(0, 2);147 blobFile = blobHash.slice(2);148 process.argv = ['', 'fvs', 'add', 'test1.txt'];149 fvs.add();150 let index = fs.readFileSync('./.fvs/index', 'utf8');151 expect(index).to.be.equal('test1.txt' + ' ' + blobHash);152 });153 });154 describe ('accepts "commit" as a command', function () {155 let blobHash,156 blobDir,157 blobFile,158 treeContent,159 treeHash,160 treeDir,161 treeFile,162 commitContent,163 commitHash,164 commitDir,165 commitFile,166 index;167 beforeEach(function () {168 fs.mkdirSync('.fvs');169 fs.mkdirSync('.fvs/objects');170 fs.writeFileSync('./test1.txt', 'test1 content', 'utf8');171 fs.mkdirSync('.fvs/refs');172 fs.writeFileSync('./.fvs/HEAD', 'refs/master');173 fs.writeFileSync('./.fvs/refs/master', '');174 blobHash = getSha1('test1 content');175 blobDir = blobHash.slice(0, 2);176 blobFile = blobHash.slice(2);177 treeContent = 'blob' + ' ' + blobHash + ' ' + 'test1.txt';178 treeHash = getSha1(treeContent);179 treeDir = treeHash.slice(0, 2);180 treeFile = treeHash.slice(2);181 commitContent = '' +182 'tree ' + treeHash + '\n' +183 'author ' + YOUR_NAME + '\n' +184 'testing';185 commitHash = getSha1(commitContent);186 commitDir = commitHash.slice(0, 2);187 commitFile = commitHash.slice(2);188 index = 'test1.txt' + ' ' + blobHash;189 fs.writeFileSync('.fvs/index', index, 'utf8');190 });191 afterEach(function () { rmdir('test1.txt'); });192 it('throws an error if a message is not defined', function () {193 process.argv = ['', 'fvs', 'commit'];194 expect(fvs.commit).to.throw('No commit message');195 });196 it('creates a tree graph to represent the content of the version of the project being committed', function () {197 process.argv = ['', 'fvs', 'commit', 'testing'];198 fvs.commit();199 let file = fs.readFileSync('./.fvs/objects/' + treeDir + '/' + treeFile, 'utf8');...
db.test.js
Source:db.test.js
...19 const testHashes = [20 "firefoxaccount@test.com",21 "unverifiedemail@test.com",22 "verifiedemail@test.com",23 ].map(email => getSha1(email));24 const subscribers = await DB.getSubscribersByHashes(testHashes);25 for (const subscriber of subscribers) {26 expect(subscriber.primary_verified).toBeTruthy();27 }28});29test("getEmailAddressesByHashes accepts hashes and only returns verified email_addresses", async () => {30 const testHashes = [31 "firefoxaccount-secondary@test.com",32 "firefoxaccount-tertiary@test.com",33 ].map(email => getSha1(email));34 const emailAddresses = await DB.getEmailAddressesByHashes(testHashes);35 for (const emailAddress of emailAddresses) {36 expect(emailAddress.verified).toBeTruthy();37 }38});39test("getEmailByToken accepts token and returns email_addresses record", async () => {40 const testEmailAddress = TEST_EMAIL_ADDRESSES.firefox_account;41 const emailAddress = await DB.getEmailByToken(testEmailAddress.verification_token);42 expect(emailAddress.email).toEqual(testEmailAddress.email);43});44test("getEmailById accepts id and returns email_addresses record", async () => {45 const testEmailAddress = TEST_EMAIL_ADDRESSES.unverified_email_on_firefox_account;46 const emailAddress = await DB.getEmailById(testEmailAddress.id);47 expect(emailAddress.email).toEqual(testEmailAddress.email);48});49test("addSubscriberUnverifiedEmailHash accepts user and email and returns unverified email_address with sha1 hash and verification token", async () => {50 const testEmail = "test@test.com";51 // https://stackoverflow.com/a/1365318052 const uuidRE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;53 const subscriber = await DB.getSubscriberByEmail("firefoxaccount@test.com");54 const unverifiedEmailAddress = await DB.addSubscriberUnverifiedEmailHash(subscriber, testEmail);55 expect(unverifiedEmailAddress.sha1).toBe(getSha1(testEmail));56 expect(uuidRE.test(unverifiedEmailAddress.verification_token)).toBeTruthy();57 expect(unverifiedEmailAddress.verified).toBeFalsy();58});59test("verifyEmailHash accepts token and returns verified subscriber", async () => {60 const testEmail = "verifyEmailHash@test.com";61 const subscriber = await DB.getSubscriberByEmail("firefoxaccount@test.com");62 const unverifiedEmailAddress = await DB.addSubscriberUnverifiedEmailHash(subscriber, testEmail);63 expect(unverifiedEmailAddress.verified).toBeFalsy();64 HIBP.subscribeHash.mockResolvedValue(true);65 const verifiedEmailAddress = await DB.verifyEmailHash(unverifiedEmailAddress.verification_token);66 expect(verifiedEmailAddress.sha1).toBe(getSha1(testEmail));67 expect(verifiedEmailAddress.verified).toBeTruthy();68});69test("verifyEmailHash accepts token and returns single verified subscriber", async () => {70 const testEmail = "verifyEmailHash@test.com";71 const subscriber = await DB.getSubscriberByEmail("firefoxaccount@test.com");72 const subscriber2 = await DB.getSubscriberByEmail("all_emails_to_primary@test.com");73 const unverifiedEmailAddress = await DB.addSubscriberUnverifiedEmailHash(subscriber, testEmail);74 expect(unverifiedEmailAddress.verified).toBeFalsy();75 const unverifiedEmailAddress2 = await DB.addSubscriberUnverifiedEmailHash(subscriber2, testEmail);76 expect(unverifiedEmailAddress2.verified).toBeFalsy();77 HIBP.subscribeHash.mockResolvedValue(true);78 const verifiedEmailAddress = await DB.verifyEmailHash(unverifiedEmailAddress.verification_token);79 expect(verifiedEmailAddress.sha1).toBe(getSha1(testEmail));80 expect(verifiedEmailAddress.verified).toBeTruthy();81 expect(unverifiedEmailAddress2.verified).toBeFalsy();82});83test("addSubscriber invalid argument", async () => {84 const testEmail = "test".repeat(255);85 await expect(DB.addSubscriber(testEmail)).rejects.toThrow("error-could-not-add-email");86});87test("addSubscriber accepts email, language and returns verified subscriber", async () => {88 const testEmail = "newfirefoxaccount@test.com";89 const verifiedSubscriber = await DB.addSubscriber(testEmail);90 expect(verifiedSubscriber.primary_email).toBe(testEmail);91 expect(verifiedSubscriber.primary_verified).toBeTruthy();92 expect(verifiedSubscriber.primary_sha1).toBe(getSha1(testEmail));93});94test("addSubscriber with existing email updates updated_at", async () => {95 const testEmail = "newfirefoxaccount@test.com";96 let verifiedSubscriber = await DB.addSubscriber(testEmail);97 expect(verifiedSubscriber.primary_email).toBe(testEmail);98 expect(verifiedSubscriber.primary_verified).toBeTruthy();99 expect(verifiedSubscriber.primary_sha1).toBe(getSha1(testEmail));100 const updatedAt = verifiedSubscriber.updated_at;101 await sleep(1000);102 verifiedSubscriber = await DB.addSubscriber(testEmail);103 expect(verifiedSubscriber.primary_email).toBe(testEmail);104 expect(verifiedSubscriber.primary_verified).toBeTruthy();105 expect(verifiedSubscriber.primary_sha1).toBe(getSha1(testEmail));106 expect(verifiedSubscriber.updated_at).not.toBe(updatedAt);107});108test("addSubscriber accepts upperCasedAddress, and returns verified subscriber with lowercase address hash", async () => {109 const testEmail = "upperCasedAddress@test.com";110 const verifiedSubscriber = await DB.addSubscriber(testEmail);111 expect(verifiedSubscriber.primary_email).toBe(testEmail);112 expect(verifiedSubscriber.primary_sha1).toBe(getSha1(testEmail.toLowerCase()));113});114test("setBreachesLastShown updates column and returns subscriber", async() => {115 const startingSubscriber = await DB.getSubscriberByEmail("firefoxaccount@test.com");116 await sleep(1000);117 await DB.setBreachesLastShownNow(startingSubscriber);118 const updatedSubscriber = await DB.getSubscriberByEmail(startingSubscriber.primary_email);119 expect (new Date(updatedSubscriber.breaches_last_shown).getTime()).toBeGreaterThan(new Date(startingSubscriber.breaches_last_shown).getTime());120});121test("setAllEmailsToPrimary updates column and returns subscriber", async() => {122 const startingSubscriber = await DB.getSubscriberByEmail("firefoxaccount@test.com");123 await DB.setAllEmailsToPrimary(startingSubscriber, false);124 const updatedSubscriber = await DB.getSubscriberByEmail(startingSubscriber.primary_email);125 expect (updatedSubscriber.all_emails_to_primary).toBeFalsy();126});127test("removeSubscriber accepts subscriber and removes everything from subscribers and email_addresses tables", async () => {128 const startingSubscriber = await DB.getSubscriberByEmail(TEST_SUBSCRIBERS.firefox_account.primary_email);129 expect(startingSubscriber.id).toEqual(TEST_SUBSCRIBERS.firefox_account.id);130 const startingEmailAddressRecord = await DB.getEmailById(TEST_EMAIL_ADDRESSES.firefox_account.id);131 expect(startingEmailAddressRecord.id).toEqual(TEST_EMAIL_ADDRESSES.firefox_account.id);132 await DB.removeSubscriber(startingSubscriber);133 const noMoreSubscribers = await DB.getSubscriberByEmail(startingSubscriber.primary_email);134 expect(noMoreSubscribers).toBeUndefined();135 const noMoreEmailAddress = await DB.getEmailById(startingEmailAddressRecord.id);136 expect(noMoreEmailAddress).toBeUndefined();137});138test("removeEmail accepts email and removes from subscribers table", async () => {139 const testEmail = "removingfirefoxaccount@test.com";140 const verifiedSubscriber = await DB.addSubscriber(testEmail);141 const subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);142 expect(subscribers.length).toEqual(1);143 await DB.removeEmail(verifiedSubscriber.primary_email);144 const noMoreSubscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);145 expect(noMoreSubscribers.length).toEqual(0);146});147test("removeEmail accepts email and removes from email_addresses table", async () => {148 const testEmailAddress = TEST_EMAIL_ADDRESSES.all_emails_to_primary;149 const emailAddress = await DB.getEmailById(testEmailAddress.id);150 expect(emailAddress.email).toEqual(testEmailAddress.email);151 await DB.removeEmail(emailAddress.email);152 const noMoreEmailAddress = await DB.getEmailById(testEmailAddress.id);153 expect(noMoreEmailAddress).toBeUndefined();...
worker.test.js
Source:worker.test.js
...141 expect(error.message).toEqual(`Cannot read path '/kiwi.js'.`);142 });143 it('simply computes SHA-1s when requested (works well with binary data)', async () => {144 expect(145 await getSha1({146 computeSha1: true,147 filePath: '/project/fruits/apple.png',148 rootDir,149 }),150 ).toEqual({sha1: '4caece539b039b16e16206ea2478f8c5ffb2ca05'});151 expect(152 await getSha1({153 computeSha1: false,154 filePath: '/project/fruits/Banana.js',155 rootDir,156 }),157 ).toEqual({sha1: null});158 expect(159 await getSha1({160 computeSha1: true,161 filePath: '/project/fruits/Banana.js',162 rootDir,163 }),164 ).toEqual({sha1: '7772b628e422e8cf59c526be4bb9f44c0898e3d1'});165 expect(166 await getSha1({167 computeSha1: true,168 filePath: '/project/fruits/Pear.js',169 rootDir,170 }),171 ).toEqual({sha1: 'c7a7a68a1c8aaf452669dd2ca52ac4a434d25552'});172 await expect(173 getSha1({computeSha1: true, filePath: '/i/dont/exist.js', rootDir}),174 ).rejects.toThrow();175 });176 it('avoids computing dependencies if not requested and Haste does not need it', async () => {177 expect(178 await worker({179 computeDependencies: false,180 filePath: '/project/fruits/Pear.js',181 hasteImplModulePath: path.resolve(__dirname, 'haste_impl.js'),182 rootDir,183 }),184 ).toEqual({185 dependencies: undefined,186 id: 'Pear',187 module: ['fruits/Pear.js', H.MODULE],...
ses.test.js
Source:ses.test.js
...16};17test("ses notification with Permanent bounce unsubscribes recipient subscriber", async () => {18 // TODO: restore tests for ["General", "NoEmail", "Suppressed"] sub types19 const testEmail = "bounce@simulator.amazonses.com";20 const testHashes = [getSha1(testEmail)];21 await DB.addSubscriber(testEmail);22 let subscribers = await DB.getSubscribersByHashes(testHashes);23 expect(subscribers.length).toEqual(1);24 const req = httpMocks.createRequest({25 method: "POST",26 url: "/ses/notification",27 body: createRequestBody("bounce"),28 });29 const resp = httpMocks.createResponse();30 await ses.notification(req, resp);31 expect(resp.statusCode).toEqual(200);32 subscribers = await DB.getSubscribersByHashes(testHashes);33 expect(subscribers.length).toEqual(0);34});35test("ses notification with Complaint unsubscribes recipient subscriber", async () => {36 const testEmail = "complaint@simulator.amazonses.com";37 await DB.addSubscriber(testEmail);38 let subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);39 expect(subscribers.length).toEqual(1);40 const req = httpMocks.createRequest({41 method: "POST",42 url: "/ses/notification",43 body: createRequestBody("complaint"),44 });45 const resp = httpMocks.createResponse();46 await ses.notification(req, resp);47 expect(resp.statusCode).toEqual(200);48 subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);49 expect(subscribers.length).toEqual(0);50});51test("ses notification with Complaint unsubscribes recipient from email_addresses", async () => {52 const testPrimaryEmail = "secondary-email-complainer@mailinator.com";53 const testSignupLanguage = "en";54 const testUser = await DB.addSubscriber(testPrimaryEmail, testSignupLanguage);55 const testEmail = "complaint@simulator.amazonses.com";56 await DB.addSubscriberUnverifiedEmailHash(testUser, testEmail);57 const req = httpMocks.createRequest({58 method: "POST",59 url: "/ses/notification",60 body: createRequestBody("complaint"),61 });62 const resp = httpMocks.createResponse();63 await ses.notification(req, resp);64 expect(resp.statusCode).toEqual(200);65 const noMoreEmailAddressRecord = await DB.getEmailAddressRecordByEmail(testEmail);66 expect(noMoreEmailAddressRecord).toBeUndefined();67});68test("ses notification with invalid signature responds with error and doesn't change subscribers", async () => {69 const testEmail = "complaint@simulator.amazonses.com";70 await DB.addSubscriber(testEmail);71 let subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);72 expect(subscribers.length).toEqual(1);73 const req = httpMocks.createRequest({74 method: "POST",75 url: "/ses/notification",76 body: createRequestBody("invalid"),77 });78 const resp = httpMocks.createResponse();79 await expect(ses.notification(req, resp)).rejects.toMatch("invalid");80 expect(resp.statusCode).toEqual(401);81 subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);82 expect(subscribers.length).toEqual(1);83});84test("sns notification for FxA account deletes monitor subscriber record", async () => {85 const testEmail = "fxa-deleter@mailinator.com";86 const testSignupLanguage = "en";87 const testFxaAccessToken = "abcdef123456789";88 const testFxaRefreshToken = "abcdef123456789";89 const testFxaUID = "3b1a9d27f85b4a4c977f3a84838f9116";90 const testFxaProfileData = JSON.stringify({uid: testFxaUID});91 await DB.addSubscriber(testEmail, testSignupLanguage, testFxaAccessToken, testFxaRefreshToken, testFxaProfileData);92 let subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);93 expect(subscribers.length).toEqual(1);94 const req = httpMocks.createRequest({95 method: "POST",96 url: "/ses/notification",97 body: createRequestBody("fxa-delete"),98 });99 const resp = httpMocks.createResponse();100 await ses.notification(req, resp);101 expect(resp.statusCode).toEqual(200);102 subscribers = await DB.getSubscribersByHashes([getSha1(testEmail)]);103 expect(subscribers.length).toEqual(0);...
update_steps.test.js
Source:update_steps.test.js
1'use strict'2jest.mock('fs')3jest.mock('../worlds/paths')4jest.mock('../worlds/read')5jest.mock('../service/restart')6jest.mock('./get_stream')7jest.mock('./get_sha1')8jest.mock('./pipe')9const { createReadStream, createWriteStream, promises } = require('fs')10const { unlink } = promises11const { getVersionPath } = require('../worlds/paths')12const { getCurrentVersion } = require('../worlds/read')13const { restart } = require('../service/restart')14const { getStream } = require('./get_stream')15const { getSha1 } = require('./get_sha1')16const { pipe } = require('./pipe')17const {18 getPathCurrentServer,19 isCurrentLatest,20 downloadLatest,21 restartIfNeeded22} = require('./update_steps')23const serverInfo = {24 latest: '1.2.3',25 url: 'url',26 sha1: 'sha1'27}28const readStream = {}29const gottenStream = {}30const writtenStream = {}31describe('update steps', () => {32 beforeEach(() => {33 getVersionPath.mockReset().mockReturnValue('versionPath')34 getCurrentVersion.mockReset().mockResolvedValue('version')35 restart.mockReset()36 getSha1.mockReset().mockResolvedValue('sha1')37 createReadStream.mockReset().mockReturnValue(readStream)38 getStream.mockReset().mockResolvedValue(gottenStream)39 createWriteStream.mockReset().mockReturnValue(writtenStream)40 })41 describe('getPathCurrentServer', () => {42 it('should return path of current server jar', () => {43 expect(getPathCurrentServer('release', serverInfo)).toBe('versionPath/server.jar')44 expect(getVersionPath).toHaveBeenCalledWith('release')45 })46 })47 describe('isCurrentLatest', () => {48 it('should return true when current and latest match SHA1', async () => {49 createReadStream.mockReturnValue(readStream)50 expect(isCurrentLatest('currentPath', serverInfo)).resolves.toEqual(true)51 expect(createReadStream).toHaveBeenCalledWith('currentPath')52 expect(getSha1).toHaveBeenCalledWith(readStream)53 })54 it('should return false when current SHA1 does not match latest', async () => {55 getSha1.mockResolvedValue('otherSha1')56 expect(isCurrentLatest('currentPath', serverInfo)).resolves.toEqual(false)57 expect(createReadStream).toHaveBeenCalledWith('currentPath')58 expect(getSha1).toHaveBeenCalledWith(readStream)59 })60 })61 describe('downloadLatest', () => {62 it('should download latest and proceed on matching sha1', async () => {63 await expect(downloadLatest('release', serverInfo)).resolves.toEqual('versionPath/server.1.2.3.jar')64 expect(pipe).toHaveBeenCalledWith(gottenStream, writtenStream)65 expect(createReadStream).toHaveBeenCalledWith('versionPath/server.1.2.3.jar')66 })67 it('should throw when latest download does not match sha1', async () => {68 getSha1.mockResolvedValue('otherSha1')69 await expect(downloadLatest('release', serverInfo)).rejects.toEqual(new Error('Latest release 1.2.3 download failed'))70 expect(unlink).toHaveBeenCalledWith('versionPath/server.1.2.3.jar')71 })72 })73 describe('restartIfNeeded', () => {74 const notify = jest.fn()75 const reconfigure = jest.fn()76 beforeEach(() => {77 notify.mockReset()78 reconfigure.mockReset()79 })80 it('should restart if replaced version is current', async () => {81 await restartIfNeeded('version', 'latest', notify, reconfigure)82 expect(restart).toHaveBeenCalledWith('Upgrading to latest', notify, reconfigure)83 })84 it('should not restart if replaced version is not current', async () => {85 await restartIfNeeded('other version', 'latest', notify, reconfigure)86 expect(restart.mock.calls.length).toBe(0)87 expect(reconfigure).toHaveBeenCalled()88 })89 })...
test_subscribers.js
Source:test_subscribers.js
2const getSha1 = require("../../sha1-utils");3exports.TEST_SUBSCRIBERS = {4 firefox_account: {5 id: 12345,6 primary_sha1: getSha1("firefoxaccount@test.com"),7 primary_email: "firefoxaccount@test.com",8 primary_verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2cf1",9 primary_verified: true,10 fxa_access_token: "4a4792b89434153f1a6262fbd6a4510c00834ff842585fc4f4d972da158f0fc0",11 fxa_refresh_token: "4a4792b89434153f1a6262fbd6a4510c00834ff842585fc4f4d972da158f0fc1",12 fxa_uid: 12345,13 fxa_profile_json: {},14 breaches_last_shown: "2019-04-24 13:27:08.421-05",15 breaches_resolved: {"firefoxaccount@test.com": [0]},16 },17 all_emails_to_primary: {18 id: 67890,19 primary_sha1: getSha1("all_emails_to_primary@test.com"),20 primary_email: "all_emails_to_primary@test.com",21 primary_verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2ca7",22 primary_verified: true,23 fxa_refresh_token: "4a4792b89434153f1a6262fbd6a4510c00834ff842585fc4f4d972da158f0fc2",24 breaches_last_shown: "2019-04-24 13:27:08.421-05",25 all_emails_to_primary: true,26 },27 unverified_email: {28 primary_sha1: getSha1("unverifiedemail@test.com"),29 primary_email: "unverifiedemail@test.com",30 primary_verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2cf0",31 primary_verified: false,32 },33 verified_email: {34 primary_sha1: getSha1("verifiedemail@test.com"),35 primary_email: "verifiedemail@test.com",36 primary_verification_token: "54010800-6c3c-4186-971a-76dc92874941",37 primary_verified: true,38 signup_language: "en-US;q=0.7,en;q=0.3",39 },40};41exports.TEST_EMAIL_ADDRESSES = {42 firefox_account: {43 id: 11111,44 subscriber_id: 12345,45 sha1: getSha1("firefoxaccount-secondary@test.com"),46 email: "firefoxaccount-secondary@test.com",47 verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2cf2",48 verified: true,49 },50 unverified_email_on_firefox_account: {51 id: 98765,52 subscriber_id: 12345,53 sha1: getSha1("firefoxaccount-tertiary@test.com"),54 email: "firefoxaccount-tertiary@test.com",55 verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2cf3",56 verified: false,57 },58 all_emails_to_primary: {59 id: 99999,60 subscriber_id: 67890,61 sha1: getSha1("secondary_sending_to_primary@test.com"),62 email: "secondary_sending_to_primary@test.com",63 verification_token: "0e2cb147-2041-4e5b-8ca9-494e773b2cf4",64 verified: true,65 },...
haste_map_sha1.test.js
Source:haste_map_sha1.test.js
...39 useWatchman: false,40 watch: false,41 });42 const {hasteFS} = await haste.build();43 expect(hasteFS.getSha1(path.join(DIR, 'file.android.js'))).toBe(44 'e376f9fd9a96d000fa019020159f996a8855f8bc',45 );46 expect(hasteFS.getSha1(path.join(DIR, 'file.ios.js'))).toBe(47 '1271b4db2a5f47ae46cb01a1d0604a94d401e8f7',48 );49 expect(hasteFS.getSha1(path.join(DIR, 'file.js'))).toBe(50 'c26c852220977244418f17a9fdc4ae9c192b3188',51 );52 expect(hasteFS.getSha1(path.join(DIR, 'node_modules/bar/image.png'))).toBe(53 '8688f7e11f63d8a7eac7cb87af850337fabbd400',54 );55 expect(hasteFS.getSha1(path.join(DIR, 'node_modules/bar/index.js'))).toBe(56 'ee245b9fbd45e1f6ad300eb2f5484844f6b5a34c',57 );58 // Ignored files do not get the SHA-1 computed.59 expect(hasteFS.getSha1(path.join(DIR, 'file_with_extension.ignored'))).toBe(60 null,61 );62 expect(63 hasteFS.getSha1(64 path.join(DIR, 'node_modules/bar/file_with_extension.ignored'),65 ),66 ).toBe(null);...
hasteMapSha1.test.js
Source:hasteMapSha1.test.js
...38 useWatchman: false,39 watch: false,40 });41 const {hasteFS} = await haste.build();42 expect(hasteFS.getSha1(path.join(DIR, 'file.android.js'))).toBe(43 'e376f9fd9a96d000fa019020159f996a8855f8bc',44 );45 expect(hasteFS.getSha1(path.join(DIR, 'file.ios.js'))).toBe(46 '1271b4db2a5f47ae46cb01a1d0604a94d401e8f7',47 );48 expect(hasteFS.getSha1(path.join(DIR, 'file.js'))).toBe(49 'c26c852220977244418f17a9fdc4ae9c192b3188',50 );51 expect(hasteFS.getSha1(path.join(DIR, 'node_modules/bar/image.png'))).toBe(52 '8688f7e11f63d8a7eac7cb87af850337fabbd400',53 );54 expect(hasteFS.getSha1(path.join(DIR, 'node_modules/bar/index.js'))).toBe(55 'ee245b9fbd45e1f6ad300eb2f5484844f6b5a34c',56 );57 // Ignored files do not get the SHA-1 computed.58 expect(hasteFS.getSha1(path.join(DIR, 'fileWithExtension.ignored'))).toBe(59 null,60 );61 expect(62 hasteFS.getSha1(63 path.join(DIR, 'node_modules/bar/fileWithExtension.ignored'),64 ),65 ).toBe(null);...
LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!