feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722)
Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the frontend spec in the folders such as `specs/<domain-name>/getters.spec.js` were not executed in Circle CI. This PR fixes the issue, along with the following changes: - Use vitest instead of jest - Remove jest dependancies - Update tests to work with vitest --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -1,21 +1,44 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { InitializationHelpers } from '../portalHelpers';
|
||||
|
||||
describe('#navigateToLocalePage', () => {
|
||||
it('returns correct cookie name', () => {
|
||||
const elemDiv = document.createElement('div');
|
||||
elemDiv.classList.add('locale-switcher');
|
||||
document.body.appendChild(elemDiv);
|
||||
describe('InitializationHelpers.navigateToLocalePage', () => {
|
||||
let dom;
|
||||
let document;
|
||||
let window;
|
||||
|
||||
const allLocaleSwitcher = document.querySelector('.locale-switcher');
|
||||
beforeEach(() => {
|
||||
dom = new JSDOM(
|
||||
'<!DOCTYPE html><html><body><div class="locale-switcher" data-portal-slug="test-slug"><select><option value="en">English</option><option value="fr">French</option></select></div></body></html>',
|
||||
{ url: 'http://localhost/' }
|
||||
);
|
||||
document = dom.window.document;
|
||||
window = dom.window;
|
||||
global.document = document;
|
||||
global.window = window;
|
||||
});
|
||||
|
||||
allLocaleSwitcher.addEventListener = jest
|
||||
.fn()
|
||||
.mockImplementationOnce((event, callback) => {
|
||||
callback({ target: { value: 1 } });
|
||||
});
|
||||
afterEach(() => {
|
||||
dom = null;
|
||||
document = null;
|
||||
window = null;
|
||||
delete global.document;
|
||||
delete global.window;
|
||||
});
|
||||
|
||||
it('should return false if .locale-switcher is not found', () => {
|
||||
document.querySelector('.locale-switcher').remove();
|
||||
const result = InitializationHelpers.navigateToLocalePage();
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should add change event listener to .locale-switcher', () => {
|
||||
const localeSwitcher = document.querySelector('.locale-switcher');
|
||||
const addEventListenerSpy = vi.spyOn(localeSwitcher, 'addEventListener');
|
||||
|
||||
InitializationHelpers.navigateToLocalePage();
|
||||
expect(allLocaleSwitcher.addEventListener).toBeCalledWith(
|
||||
|
||||
expect(addEventListenerSpy).toHaveBeenCalledWith(
|
||||
'change',
|
||||
expect.any(Function)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user