Skip to content

Commit

Permalink
Move newtab-tracker-stats tests to esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
sammacbeth committed Jul 19, 2023
1 parent 96e7d38 commit c42ca7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { NewTabTrackerStats } = require('../../shared/js/background/newtab-tracker-stats')
const { TrackerStats } = require('../../shared/js/background/classes/tracker-stats')
const browserWrapper = require('../../shared/js/background/wrapper')
const constants = require('../../shared/data/constants')
const testTDS = require('../data/tds.json')
const { dataFormatSchema } = require('../../shared/js/newtab/schema')
Expand Down Expand Up @@ -116,6 +115,11 @@ describe('NewTabTrackerStats', () => {
describe('sending data', () => {
beforeEach(() => {
jasmine.clock().install()
// @ts-ignore
while (chrome.storage.local._setCalls.length > 0) {
// @ts-ignore
chrome.storage.local._setCalls.pop()
}
})
afterEach(() => {
jasmine.clock().uninstall()
Expand All @@ -127,7 +131,8 @@ describe('sending data', () => {
// @ts-ignore
newtab.assignTopCompanies(testTDS.entities)
const sendSpy = spyOn(newtab, '_publish')
const syncSpy = spyOn(browserWrapper, 'syncToStorage')
// @ts-ignore
const syncSpy = chrome.storage.local._setCalls

const now = 1673473220560

Expand All @@ -145,8 +150,8 @@ describe('sending data', () => {
expect(sendSpy).toHaveBeenCalledTimes(1)

// assert that values were synced to storage
expect(syncSpy).toHaveBeenCalledTimes(1)
expect(syncSpy).toHaveBeenCalledWith({
expect(syncSpy.length).toBe(1)
expect(syncSpy[0]).toEqual({
[NewTabTrackerStats.storageKey]: {
stats: {
current: {
Expand Down
10 changes: 8 additions & 2 deletions unit-test/helpers/mock-browser-api.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
globalThis.browser = {
storage: {
local: {
set: () => {},
set: (value) => {
browser.storage.local._setCalls.push(value)
},
get: () => {
return {}
}
},
_setCalls: []
},
managed: {
get: () => {}
}
},
browserAction: {
Expand Down
10 changes: 8 additions & 2 deletions unit-test/inject-chrome-shim.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const chrome = {
storage: {
local: {
set: () => {},
set: (value) => {
chrome.storage.local._setCalls.push(value)
},
get: () => {
return {}
}
},
_setCalls: []
},
managed: {
get: () => {}
}
},
browserAction: {
Expand Down

0 comments on commit c42ca7a

Please sign in to comment.