Skip to content

Commit

Permalink
[core] Refactor tests license setting (#13076)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasTy authored May 10, 2024
1 parent e3e8a5f commit ac189d7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@mui/x-data-grid-pro": "workspace:*",
"@mui/x-date-pickers": "workspace:*",
"@mui/x-date-pickers-pro": "workspace:*",
"@mui/x-license": "workspace:*",
"@react-spring/web": "^9.7.3",
"@playwright/test": "^1.43.1",
"@types/chai": "^4.3.16",
Expand Down
9 changes: 3 additions & 6 deletions test/regressions/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import { LicenseInfo } from '@mui/x-license';
import TestViewer from 'test/regressions/TestViewer';
import { useFakeTimers } from 'sinon';
import { Globals } from '@react-spring/web';
// This license key is only valid for use with Material UI SAS's projects
// See the terms: https://mui.com/r/x-license-eula
LicenseInfo.setLicenseKey(
'e43ff101678711136a9b81c18047cb69Tz1NVUktRG9jLEU9MTc0Njc4NzYxODIwMSxTPXByZW1pdW0sTE09c3Vic2NyaXB0aW9uLEtWPTI=',
);
import { setupTestLicenseKey } from '../utils/testLicense';

setupTestLicenseKey();

Globals.assign({
skipAnimation: true,
Expand Down
16 changes: 9 additions & 7 deletions test/utils/mochaHooks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sinon from 'sinon';
import { LicenseInfo } from '@mui/x-license';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGrid } from '@mui/x-data-grid';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGridPro } from '@mui/x-data-grid-pro';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingTreeView } from '@mui/x-tree-view';
import { clearWarningsCache } from '@mui/x-data-grid/internals';
import { generateTestLicenseKey, setupTestLicenseKey } from './testLicense';

export function createXMochaHooks(coreMochaHooks = {}) {
const mochaHooks = {
Expand All @@ -13,12 +13,14 @@ export function createXMochaHooks(coreMochaHooks = {}) {
afterEach: [...(coreMochaHooks.afterEach ?? [])],
};

mochaHooks.beforeEach.push(function setLicenseKey() {
// This license key is only valid for use with Material UI SAS's projects
// See the terms: https://mui.com/r/x-license-eula
LicenseInfo.setLicenseKey(
'e43ff101678711136a9b81c18047cb69Tz1NVUktRG9jLEU9MTc0Njc4NzYxODIwMSxTPXByZW1pdW0sTE09c3Vic2NyaXB0aW9uLEtWPTI=',
);
let licenseKey;

mochaHooks.beforeAll.push(function func() {
licenseKey = generateTestLicenseKey();
});

mochaHooks.beforeEach.push(function setupLicenseKey() {
setupTestLicenseKey(licenseKey);
});

mochaHooks.afterEach.push(function resetCleanupTracking() {
Expand Down
18 changes: 18 additions & 0 deletions test/utils/testLicense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LicenseInfo, generateLicense } from '@mui/x-license';

export function generateTestLicenseKey() {
const expiryDate = new Date();
// Set the expiry date to 1 hour from now just to be on the safe side.
// Tests usually take up to 15 minutes to run on CI.
expiryDate.setHours(expiryDate.getHours() + 1);
return generateLicense({
licensingModel: 'subscription',
scope: 'premium',
orderNumber: 'MUI X tests',
expiryDate,
});
}

export function setupTestLicenseKey(licenseKey = generateTestLicenseKey()) {
LicenseInfo.setLicenseKey(licenseKey);
}

0 comments on commit ac189d7

Please sign in to comment.