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

OKTA-656562 karma to jest #3418

Merged

Conversation

glenfannin-okta
Copy link
Contributor

@glenfannin-okta glenfannin-okta commented Oct 16, 2023

Description:

The purpose of this PR is to migrate all tests that currently use karma (referenced in legacy-tests.js) to use jest and to remove all karma dependencies.

PR Checklist

Issue:

Reviewers:

Screenshot/Video:

Downstream Monolith Build:

.testcaferc.js Outdated Show resolved Hide resolved
@@ -7,7 +7,7 @@ export TEST_RESULT_FILE_DIR="${REPO}/build2/reports/unit"
echo $TEST_SUITE_TYPE > $TEST_SUITE_TYPE_FILE
echo $TEST_RESULT_FILE_DIR > $TEST_RESULT_FILE_DIR_FILE

if ! yarn test --type jest --runInBand; then
Copy link
Contributor

Choose a reason for hiding this comment

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

was --runInBand causing issues? This is actually good though since it should run tests concurrently (faster overall)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, using the --runInBand flag caused the test to timeout (it took > 30mins to actually complete). When I looked up what the flag was meant for I realized we did not need it in bacon (only during debuggin). This decreased the time to ~10 mins

test/unit/spec/v1/Animations_spec.js Show resolved Hide resolved

global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
global.crypto = new Crypto();
global.$ = global.jQuery = $;
global.DEBUG = false;
global.getJasmineRequireObj = function jestSetupGlobalJasmine() {
return jasmine;
};
global.jasmine = jasmine;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should follow up separately to remove jasmine as it's very confusing to know if a call to something like spyOn is from jasmine or from jest. Additionally, the interface of the returned Spy object is different between jasmine and jest's versions so would be good to migrate so we don't need to keep jasmine in our devDeps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will create a ticket for this, maybe we can actually add it as another UI Guild rotation task 🤔

test/unit/spec/v1/EnrollCall_spec.js Outdated Show resolved Hide resolved
test/unit/spec/v1/EnrollSms_spec.js Show resolved Hide resolved
// Verify tooltip is gone
expect(test.form.isSecurityImageTooltipDestroyed()).toBe(true);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the deleted tests in this file moved someplace else or are they removed entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test/unit/spec/v1/PrimaryAuth_spec.js Outdated Show resolved Hide resolved
.then(function() {
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: true }));
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

deleted tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -3296,7 +3198,7 @@ Expect.describe('PrimaryAuth', function() {
// cannot mock it because we defer to AuthJs to do set window.location.
// On the plus side, there is an e2e test that covers this.
// eslint-disable-next-line jasmine/no-disabled-tests
xit('redirects to the correct url in the social idp redirect flow');
Copy link
Contributor

Choose a reason for hiding this comment

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

should this stay uncommented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleting this since there is already an e2e test that covers this.

// patch jquery 3 visible pseudos selector issue in jsdom
// https://github.com/jsdom/jsdom/issues/1048#issuecomment-401599392
// https://github.com/jsdom/jsdom/issues/1048#issuecomment-595961496
window.Element.prototype.getClientRects = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any workaround to avoiding using jquery to do the check for :visible instead of having to polyfill this behavior for jsdom?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would need to upate code within Gen 1 to not use the visible selector, this is one example where we are using the visible selector, but it is also used by JQuery qtip.

Comment on lines -470 to -476
itp('sets aria-expanded attribute correctly when clicking help', function() {
return setup().then(function(test) {
expect(test.form.helpFooter().attr('aria-expanded')).toBe('false');
test.form.helpFooter().click();
expect(test.form.helpFooter().attr('aria-expanded')).toBe('true');
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved into PrimaryAuthForm_spec.js

Comment on lines -1130 to -1178
itp('does not show anti-phishing message if security image is hidden', function() {
return setup({ features: { securityImage: true } })
.then(function(test) {
test.setNextResponse(resSecurityImageFail);
test.form.securityBeaconContainer().hide();
spyOn($.qtip.prototype, 'toggle').and.callThrough();
test.form.setUsername('testuser@clouditude.net');
$(window).trigger('resize');
return waitForBeaconChange(test);
})
.then(function(test) {
expect($.qtip.prototype.toggle.calls.count()).toBe(1);
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: false }));
$.qtip.prototype.toggle.calls.reset();
test.form.securityBeaconContainer().show();
$(window).trigger('resize');
return Expect.waitForSpyCall($.qtip.prototype.toggle);
})
.then(function() {
expect($.qtip.prototype.toggle.calls.count()).toBe(1);
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: true }));
});
});
itp('show anti-phishing message if security image become visible', function() {
return setup({ features: { securityImage: true } })
.then(function(test) {
spyOn($.qtip.prototype, 'toggle').and.callThrough();
test.setNextResponse(resSecurityImageFail);
test.form.setUsername('testuser@clouditude.net');
return waitForBeaconChange(test);
})
.then(function(test) {
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: true }));
$.qtip.prototype.toggle.calls.reset();
test.form.securityBeaconContainer().hide();
$(window).trigger('resize');
return Expect.waitForSpyCall($.qtip.prototype.toggle, test);
})
.then(function(test) {
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: false }));
$.qtip.prototype.toggle.calls.reset();
test.form.securityBeaconContainer().show();
$(window).trigger('resize');
return Expect.waitForSpyCall($.qtip.prototype.toggle, test);
})
.then(function() {
expect($.qtip.prototype.toggle.calls.argsFor(0)).toEqual(jasmine.objectContaining({ 0: true }));
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

testEnrollPhoneNumber(setup, resEnrollSuccess);
});

describe('Verify phone number', function() {
beforeEach(() => {
jest.setTimeout(20000);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking also to see if these extra timeouts can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep these can be removed, pushing update and did a search for all usage of this settimeout to test the removal of those as well 🙏


// jsdom has issue with :visible selector
// check visibility recursively instead
if (global.useJest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove this conditional and the "jquery method" now? i see the jest setup file sets this true

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.

None yet

5 participants