Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to vitest #235

Merged
merged 7 commits into from
Jul 3, 2024
Merged

move to vitest #235

merged 7 commits into from
Jul 3, 2024

Conversation

hans-lizihan
Copy link
Contributor

@hans-lizihan hans-lizihan commented Jun 22, 2024

vitest requires node version 18. so updated workflow.yaml as well.

@@ -191,11 +191,11 @@ class MixpanelPeople extends ProfileHelpers() {
*/
track_charge(distinct_id, amount, properties, modifiers, callback) {
if (typeof(properties) === 'function' || !properties) {
callback = properties || function() {};
callback = properties || undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure the callback is conditionally passed in send_request

Copy link
Member

@tdumitrescu tdumitrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Surprised to see coverage is already so good. Just a bit of cleanup suggested but largely good to go

test/alias.js Outdated
describe('alias', () => {
let mixpanel;
let sendRequestMock;
beforeAll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
beforeAll(() => {
beforeEach(() => {

test/config.js Outdated

describe('config', () => {
let mixpanel;
beforeAll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also make this one a beforeEach - make sure each test case has a fresh mp instance

test/import.js Outdated

"calls send_request with correct endpoint and data": function(test) {
var event = "test",
six_days_ago_timestamp = mock_now_time - 1000 * 60 * 60 * 24 * 6;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
six_days_ago_timestamp = mock_now_time - 1000 * 60 * 60 * 24 * 6;
six_days_ago_timestamp = mock_now_time - 1000 * 60 * 60 * 24 * 6;

test/import.js Outdated

describe('import', () => {
let mixpanel;
beforeAll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
beforeAll(() => {
beforeEach(() => {

test/import.js Outdated

vi.spyOn(mixpanel, 'send_request');
}),
afterAll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this func from the before-func, for consistency with your other tests

test/import.js Outdated

next();
},
afterEach(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return from before-func

test/people.js Outdated
send_request = vi.fn();

mixpanel = Mixpanel.init(token);
mixpanel.send_request = send_request
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you're inconsistent between using this approach and vi.spyOn(mixpanel, 'send_request'). I would think spyOn is preferable, but is there some context I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.. i think when i did the conversion, this was the way sinon stubs this function.

let mixpanel;
let http_emitter;
let res;
beforeEach((next) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
beforeEach((next) => {
beforeEach(() => {

var event = "test",
describe('track', () => {
let mixpanel;
beforeAll(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
beforeAll(() => {
beforeEach(() => {

@hans-lizihan
Copy link
Contributor Author

@tdumitrescu updated

Copy link
Member

@tdumitrescu tdumitrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@hans-lizihan hans-lizihan merged commit 261a98b into mixpanel:master Jul 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants