chore: default hashed (#37154)

* chore: default hashed

* test: try for clean default hashed

* chore: clean up

* chore: fix dist

* chore: es inject

* chore: no hashed in test env

* chore: update comment

* chore: hack in jest env

* chore: try unique entry
pull/37089/head
二货爱吃白萝卜 2 years ago committed by GitHub
parent 9b3a4dab70
commit 78cca16779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,5 @@
/* eslint-disable import/prefer-default-export */
import { useToken as useInternalToken } from '.';
import { useToken as useInternalToken, defaultConfig } from '.';
import defaultAlgorithm from './themes/default';
import darkAlgorithm from './themes/dark';
import { defaultAlgorithmV4, darkAlgorithmV4 } from './themes/v4';
@ -15,6 +15,9 @@ function useToken() {
}
export default {
/** @private Test Usage. Do not use in production. */
defaultConfig,
useToken,
defaultAlgorithm,
darkAlgorithm,

@ -41,14 +41,18 @@ export type {
};
// ================================ Context =================================
// To ensure snapshot stable. We disable hashed in test env.
export const defaultConfig = {
token: defaultSeedToken,
hashed: true,
};
export const DesignTokenContext = React.createContext<{
token: Partial<SeedToken>;
theme?: Theme<SeedToken, MapToken>;
override?: OverrideToken;
hashed?: string | boolean;
}>({
token: defaultSeedToken,
});
}>(defaultConfig);
// ================================== Hook ==================================
// In dev env, we refresh salt per hour to avoid user use this

@ -1,4 +1,26 @@
import { toHaveNoViolations } from 'jest-axe';
import '@testing-library/jest-dom';
import { defaultConfig } from '../components/theme/index';
// Not use dynamic hashed for test env since version will change hash dynamically.
defaultConfig.hashed = false;
if (process.env.LIB_DIR === 'dist') {
jest.mock('../dist/antd', () => {
const antd = jest.requireActual('../dist/antd');
antd.theme.defaultConfig.hashed = false;
return antd;
});
} else if (process.env.LIB_DIR === 'es') {
jest.mock('../es/theme', () => {
const esTheme = jest.requireActual('../es/theme');
if (esTheme.defaultConfig) {
esTheme.defaultConfig.hashed = false;
}
return esTheme;
});
}
expect.extend(toHaveNoViolations);

Loading…
Cancel
Save