Match-id-98d57021687fe19f8559b6833caed34bdb1d1e39
This commit is contained in:
commit
d820471f30
|
@ -6,7 +6,6 @@ module.exports = {
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
['@babel/plugin-proposal-class-properties', { loose: true }],
|
['@babel/plugin-proposal-class-properties', { loose: true }],
|
||||||
'syntax-trailing-function-commas',
|
|
||||||
[
|
[
|
||||||
'@babel/plugin-proposal-object-rest-spread',
|
'@babel/plugin-proposal-object-rest-spread',
|
||||||
{ loose: true, useBuiltIns: true },
|
{ loose: true, useBuiltIns: true },
|
||||||
|
@ -34,6 +33,5 @@ module.exports = {
|
||||||
pragma: 'Horizon.createElement',
|
pragma: 'Horizon.createElement',
|
||||||
pragmaFrag: 'Horizon.Fragment'
|
pragmaFrag: 'Horizon.Fragment'
|
||||||
}],
|
}],
|
||||||
'@babel/plugin-transform-flow-strip-types',
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
165
jest.config.js
165
jest.config.js
|
@ -1,183 +1,18 @@
|
||||||
// For a detailed explanation regarding each configuration property, visit:
|
|
||||||
// https://jestjs.io/docs/en/configuration.html
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// All imported modules in your tests should be mocked automatically
|
|
||||||
// automock: false,
|
|
||||||
|
|
||||||
// Stop running tests after `n` failures
|
|
||||||
// bail: 0,
|
|
||||||
|
|
||||||
// Respect "browser" field in package.json when resolving modules
|
|
||||||
// browser: false,
|
|
||||||
|
|
||||||
// The directory where Jest should store its cached dependency information
|
|
||||||
// cacheDirectory: "",
|
|
||||||
|
|
||||||
// Automatically clear mock calls and instances between every test
|
|
||||||
// clearMocks: false,
|
|
||||||
|
|
||||||
// Indicates whether the coverage information should be collected while executing the test
|
|
||||||
// collectCoverage: false,
|
|
||||||
|
|
||||||
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
||||||
// collectCoverageFrom: undefined,
|
|
||||||
|
|
||||||
// The directory where Jest should output its coverage files
|
|
||||||
coverageDirectory: 'coverage',
|
coverageDirectory: 'coverage',
|
||||||
|
|
||||||
// An array of regexp pattern strings used to skip coverage collection
|
|
||||||
// coveragePathIgnorePatterns: [
|
|
||||||
// "\\\\node_modules\\\\"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// A list of reporter names that Jest uses when writing coverage reports
|
|
||||||
// coverageReporters: [
|
|
||||||
// "json",
|
|
||||||
// "text",
|
|
||||||
// "lcov",
|
|
||||||
// "clover"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An object that configures minimum threshold enforcement for coverage results
|
|
||||||
// coverageThreshold: undefined,
|
|
||||||
|
|
||||||
// A path to a custom dependency extractor
|
|
||||||
// dependencyExtractor: undefined,
|
|
||||||
|
|
||||||
// Make calling deprecated APIs throw helpful error messages
|
|
||||||
// errorOnDeprecated: false,
|
|
||||||
|
|
||||||
// Force coverage collection from ignored files using an array of glob patterns
|
|
||||||
// forceCoverageMatch: [],
|
|
||||||
|
|
||||||
// A path to a module which exports an async function that is triggered once before all test suites
|
|
||||||
// globalSetup: undefined,
|
|
||||||
|
|
||||||
// A path to a module which exports an async function that is triggered once after all test suites
|
|
||||||
// globalTeardown: undefined,
|
|
||||||
|
|
||||||
// A set of global variables that need to be available in all test environments
|
|
||||||
// globals: {},
|
|
||||||
|
|
||||||
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
||||||
// maxWorkers: "50%",
|
|
||||||
|
|
||||||
// An array of directory names to be searched recursively up from the requiring module's location
|
|
||||||
// moduleDirectories: [
|
|
||||||
// "node_modules"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An array of file extensions your modules use
|
|
||||||
// moduleFileExtensions: [
|
|
||||||
// 'js',
|
|
||||||
// 'ts'
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
||||||
// moduleNameMapper: {},
|
|
||||||
|
|
||||||
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
||||||
// modulePathIgnorePatterns: [],
|
|
||||||
|
|
||||||
// Activates notifications for test results
|
|
||||||
// notify: false,
|
|
||||||
|
|
||||||
// An enum that specifies notification mode. Requires { notify: true }
|
|
||||||
// notifyMode: "failure-change",
|
|
||||||
|
|
||||||
// A preset that is used as a base for Jest's configuration
|
|
||||||
// preset: undefined,
|
|
||||||
|
|
||||||
// Run tests from one or more projects
|
|
||||||
// projects: undefined,
|
|
||||||
|
|
||||||
// Use this configuration option to add custom reporters to Jest
|
|
||||||
// reporters: undefined,
|
|
||||||
|
|
||||||
// Automatically reset mock state between every test
|
|
||||||
// resetMocks: false,
|
|
||||||
|
|
||||||
// Reset the module registry before running each individual test
|
|
||||||
resetModules: true,
|
resetModules: true,
|
||||||
|
|
||||||
// A path to a custom resolver
|
|
||||||
// resolver: undefined,
|
|
||||||
|
|
||||||
// Automatically restore mock state between every test
|
|
||||||
// restoreMocks: false,
|
|
||||||
|
|
||||||
// The root directory that Jest should scan for tests and modules within
|
|
||||||
rootDir: process.cwd(),
|
rootDir: process.cwd(),
|
||||||
|
|
||||||
// A list of paths to directories that Jest should use to search for files in
|
|
||||||
// roots: [
|
|
||||||
// '<rootDir>/scripts'
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// Allows you to use a custom runner instead of Jest's default test runner
|
|
||||||
// runner: "jest-runner",
|
|
||||||
|
|
||||||
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
||||||
setupFiles: [require.resolve('./scripts/__tests__/jest/jestEnvironment.js')],
|
setupFiles: [require.resolve('./scripts/__tests__/jest/jestEnvironment.js')],
|
||||||
|
|
||||||
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
||||||
setupFilesAfterEnv: [require.resolve('./scripts/__tests__/jest/jestSetting.js')],
|
setupFilesAfterEnv: [require.resolve('./scripts/__tests__/jest/jestSetting.js')],
|
||||||
|
|
||||||
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
||||||
// snapshotSerializers: [],
|
|
||||||
|
|
||||||
// The test environment that will be used for testing
|
|
||||||
testEnvironment: 'jest-environment-jsdom-sixteen',
|
testEnvironment: 'jest-environment-jsdom-sixteen',
|
||||||
|
|
||||||
// Options that will be passed to the testEnvironment
|
|
||||||
// testEnvironmentOptions: {},
|
|
||||||
|
|
||||||
// Adds a location field to test results
|
|
||||||
// testLocationInResults: false,
|
|
||||||
|
|
||||||
// The glob patterns Jest uses to detect test files
|
|
||||||
testMatch: [
|
testMatch: [
|
||||||
'<rootDir>/scripts/__tests__/**/*.test.js'
|
'<rootDir>/scripts/__tests__/**/*.test.js'
|
||||||
],
|
],
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
||||||
// testPathIgnorePatterns: [
|
|
||||||
// "\\\\node_modules\\\\"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
||||||
//testRegex: ['/scripts/jest/dont-run-jest-directly\\.js$'],
|
|
||||||
|
|
||||||
// This option allows the use of a custom results processor
|
|
||||||
// testResultsProcessor: undefined,
|
|
||||||
|
|
||||||
// This option allows use of a custom test runner
|
|
||||||
// testRunner: "jasmine2",
|
|
||||||
|
|
||||||
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
||||||
// testURL: "http://localhost",
|
|
||||||
|
|
||||||
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
||||||
timers: 'fake',
|
timers: 'fake',
|
||||||
|
|
||||||
// A map from regular expressions to paths to transformers
|
|
||||||
// transform: undefined,
|
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
||||||
// transformIgnorePatterns: [
|
|
||||||
// "\\\\node_modules\\\\"
|
|
||||||
// ],
|
|
||||||
|
|
||||||
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
||||||
// unmockedModulePathPatterns: undefined,
|
|
||||||
|
|
||||||
// Indicates whether each individual test should be reported during the run
|
|
||||||
// verbose: undefined,
|
|
||||||
|
|
||||||
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
||||||
// watchPathIgnorePatterns: [],
|
|
||||||
|
|
||||||
// Whether to use watchman for file crawling
|
|
||||||
// watchman: true,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"@babel/plugin-syntax-import-meta": "^7.2.0",
|
"@babel/plugin-syntax-import-meta": "^7.2.0",
|
||||||
"@babel/plugin-syntax-jsx": "^7.2.0",
|
"@babel/plugin-syntax-jsx": "^7.2.0",
|
||||||
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
|
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
|
||||||
|
"@babel/traverse": "^7.11.0",
|
||||||
"@babel/preset-env": "^7.16.11",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"@babel/types": "^7.0.0",
|
"@babel/types": "^7.0.0",
|
||||||
"babel-plugin-tester": "^10.1.0"
|
"babel-plugin-tester": "^10.1.0"
|
||||||
|
|
94
package.json
94
package.json
|
@ -15,85 +15,49 @@
|
||||||
"watch-test": "yarn test --watch --dev"
|
"watch-test": "yarn test --watch --dev"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.10.5",
|
"@babel/core": "7.16.7",
|
||||||
"@babel/code-frame": "^7.10.4",
|
"@babel/plugin-proposal-class-properties": "7.16.7",
|
||||||
"@babel/core": "^7.11.1",
|
"@babel/plugin-proposal-nullish-coalescing-operator": "7.16.7",
|
||||||
"@babel/eslint-parser": "^7.11.4",
|
"@babel/plugin-proposal-object-rest-spread": "7.16.7",
|
||||||
"@babel/helper-module-imports": "^7.10.4",
|
"@babel/plugin-proposal-optional-chaining": "7.16.7",
|
||||||
"@babel/parser": "^7.11.3",
|
"@babel/plugin-syntax-jsx": "7.16.7",
|
||||||
"@babel/plugin-external-helpers": "^7.10.4",
|
"@babel/plugin-transform-arrow-functions": "7.16.7",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
"@babel/plugin-transform-block-scoped-functions": "7.16.7",
|
||||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
"@babel/plugin-transform-block-scoping": "7.16.7",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
"@babel/plugin-transform-classes": "7.16.7",
|
||||||
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
"@babel/plugin-transform-computed-properties": "7.16.7",
|
||||||
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
"@babel/plugin-transform-destructuring": "7.16.7",
|
||||||
"@babel/plugin-syntax-jsx": "^7.10.4",
|
"@babel/plugin-transform-for-of": "7.16.7",
|
||||||
"@babel/plugin-transform-arrow-functions": "^7.10.4",
|
"@babel/plugin-transform-literals": "7.16.7",
|
||||||
"@babel/plugin-transform-async-to-generator": "^7.10.4",
|
"@babel/plugin-transform-object-super": "7.16.7",
|
||||||
"@babel/plugin-transform-block-scoped-functions": "^7.10.4",
|
"@babel/plugin-transform-parameters": "7.16.7",
|
||||||
"@babel/plugin-transform-block-scoping": "^7.11.1",
|
"@babel/plugin-transform-runtime": "7.16.7",
|
||||||
"@babel/plugin-transform-classes": "^7.14.2",
|
"@babel/plugin-transform-shorthand-properties": "7.16.7",
|
||||||
"@babel/plugin-transform-computed-properties": "^7.10.4",
|
"@babel/plugin-transform-spread": "7.16.7",
|
||||||
"@babel/plugin-transform-destructuring": "^7.10.4",
|
"@babel/plugin-transform-template-literals": "7.16.7",
|
||||||
"@babel/plugin-transform-for-of": "^7.10.4",
|
"@babel/preset-env": "7.16.7",
|
||||||
"@babel/plugin-transform-literals": "^7.10.4",
|
"@babel/preset-react": "7.16.7",
|
||||||
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
|
"@babel/preset-typescript": "7.16.7",
|
||||||
"@babel/plugin-transform-object-super": "^7.10.4",
|
|
||||||
"@babel/plugin-transform-parameters": "^7.10.5",
|
|
||||||
"@babel/plugin-transform-react-jsx-source": "^7.10.5",
|
|
||||||
"@babel/plugin-transform-runtime": "^7.14.5",
|
|
||||||
"@babel/plugin-transform-shorthand-properties": "^7.10.4",
|
|
||||||
"@babel/plugin-transform-spread": "^7.11.0",
|
|
||||||
"@babel/plugin-transform-template-literals": "^7.10.5",
|
|
||||||
"@babel/preset-env": "^7.16.11",
|
|
||||||
"@babel/preset-flow": "^7.10.4",
|
|
||||||
"@babel/preset-react": "^7.16.7",
|
|
||||||
"@babel/preset-typescript": "^7.16.7",
|
|
||||||
"@babel/register": "^7.14.5",
|
|
||||||
"@babel/traverse": "^7.11.0",
|
|
||||||
"@mattiasbuelens/web-streams-polyfill": "^0.3.2",
|
|
||||||
"@rollup/plugin-babel": "^5.3.1",
|
"@rollup/plugin-babel": "^5.3.1",
|
||||||
"@rollup/plugin-node-resolve": "^13.3.0",
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
||||||
"@rollup/plugin-replace": "^4.0.0",
|
"@rollup/plugin-replace": "^4.0.0",
|
||||||
"@types/jest": "^26.0.24",
|
"@types/jest": "^26.0.24",
|
||||||
"@types/node": "^17.0.18",
|
"@types/node": "^17.0.18",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.15.0",
|
"@typescript-eslint/eslint-plugin": "4.8.0",
|
||||||
"@typescript-eslint/parser": "^5.15.0",
|
"@typescript-eslint/parser": "4.8.0",
|
||||||
"babel-core": "^6.26.3",
|
|
||||||
"babel-eslint": "^10.0.3",
|
|
||||||
"babel-jest": "^27.5.1",
|
"babel-jest": "^27.5.1",
|
||||||
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
|
"eslint": "7.13.0",
|
||||||
"babel-preset-env": "^1.7.0",
|
|
||||||
"babel-preset-react": "^6.24.1",
|
|
||||||
"chalk": "^3.0.0",
|
|
||||||
"confusing-browser-globals": "^1.0.9",
|
|
||||||
"core-js": "^3.6.4",
|
|
||||||
"danger": "^9.2.10",
|
|
||||||
"ejs": "^3.1.6",
|
|
||||||
"error-stack-parser": "^2.0.6",
|
|
||||||
"eslint": "^7.32.0",
|
|
||||||
"eslint-config-prettier": "^6.9.0",
|
"eslint-config-prettier": "^6.9.0",
|
||||||
"eslint-plugin-babel": "^5.3.0",
|
|
||||||
"eslint-plugin-flowtype": "^2.25.0",
|
|
||||||
"eslint-plugin-jest": "^22.15.0",
|
"eslint-plugin-jest": "^22.15.0",
|
||||||
"eslint-plugin-no-for-of-loops": "^1.0.0",
|
"eslint-plugin-no-for-of-loops": "^1.0.0",
|
||||||
"eslint-plugin-no-function-declare-after-return": "^1.0.0",
|
"eslint-plugin-no-function-declare-after-return": "^1.0.0",
|
||||||
"eslint-plugin-react": "^6.7.1",
|
"eslint-plugin-react": "7.14.3",
|
||||||
"jest": "^25.5.4",
|
"jest": "^25.5.4",
|
||||||
"jest-cli": "^25.2.7",
|
|
||||||
"jest-diff": "^25.2.6",
|
|
||||||
"jest-environment-jsdom-sixteen": "^1.0.3",
|
"jest-environment-jsdom-sixteen": "^1.0.3",
|
||||||
"jest-react": "^0.12.0",
|
"prettier": "2.6.2",
|
||||||
"jest-snapshot-serializer-raw": "^1.1.0",
|
|
||||||
"minimist": "^1.2.3",
|
|
||||||
"object-assign": "^4.1.1",
|
|
||||||
"prettier": "1.19.1",
|
|
||||||
"react-lifecycles-compat": "^3.0.4",
|
|
||||||
"regenerator-runtime": "^0.13.9",
|
|
||||||
"rimraf": "^3.0.0",
|
|
||||||
"rollup": "^2.75.5",
|
"rollup": "^2.75.5",
|
||||||
"rollup-plugin-terser": "^7.0.2",
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
"typescript": "^3.9.7"
|
"typescript": "4.2.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.x",
|
"node": ">=10.x",
|
||||||
|
|
|
@ -10,14 +10,6 @@ function dispatchChangeEvent(input) {
|
||||||
|
|
||||||
describe('事件', () => {
|
describe('事件', () => {
|
||||||
const LogUtils = TestUtils.getLogUtils();
|
const LogUtils = TestUtils.getLogUtils();
|
||||||
it('根节点挂载全量事件', () => {
|
|
||||||
const App = () => {
|
|
||||||
return <div />;
|
|
||||||
};
|
|
||||||
Horizon.render(<App />, container);
|
|
||||||
console.log(TestUtils.getEventListeners(container));
|
|
||||||
//expect(TestUtils.getEventListeners(container)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('事件捕获与冒泡', () => {
|
it('事件捕获与冒泡', () => {
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {
|
||||||
createStore,
|
createStore,
|
||||||
applyMiddleware,
|
applyMiddleware,
|
||||||
combineReducers,
|
combineReducers,
|
||||||
bindActionCreators
|
bindActionCreators,
|
||||||
} from '../../../../libs/horizon/src/horizonx/adapters/redux';
|
} from '../../../../libs/horizon/src/horizonx/adapters/redux';
|
||||||
|
|
||||||
describe('Redux adapter', () => {
|
describe('Redux adapter', () => {
|
||||||
|
@ -12,21 +12,21 @@ describe('Redux adapter', () => {
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
expect(reduxStore.getState()).toBe(0);
|
expect(reduxStore.getState()).toBe(0);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('Should use default state, dispatch action and update state', async () => {
|
it('Should use default state, dispatch action and update state', async () => {
|
||||||
const reduxStore = createStore((state, action) => {
|
const reduxStore = createStore((state, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case('ADD'):
|
case 'ADD':
|
||||||
return {counter: state.counter + 1}
|
return { counter: state.counter + 1 };
|
||||||
default:
|
default:
|
||||||
return {counter: 0};
|
return { counter: 0 };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(0);
|
expect(reduxStore.getState().counter).toBe(0);
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(1);
|
expect(reduxStore.getState().counter).toBe(1);
|
||||||
});
|
});
|
||||||
|
@ -35,37 +35,37 @@ describe('Redux adapter', () => {
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
const reduxStore = createStore((state = 0, action) => {
|
const reduxStore = createStore((state = 0, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case('ADD'):
|
case 'ADD':
|
||||||
return state + 1
|
return state + 1;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
expect(counter).toBe(0);
|
expect(counter).toBe(0);
|
||||||
expect(reduxStore.getState()).toBe(1);
|
expect(reduxStore.getState()).toBe(1);
|
||||||
const unsubscribe = reduxStore.subscribe(() => {
|
const unsubscribe = reduxStore.subscribe(() => {
|
||||||
counter++;
|
counter++;
|
||||||
});
|
});
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
expect(counter).toBe(2);
|
expect(counter).toBe(2);
|
||||||
expect(reduxStore.getState()).toBe(3);
|
expect(reduxStore.getState()).toBe(3);
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
expect(counter).toBe(2);
|
expect(counter).toBe(2);
|
||||||
expect(reduxStore.getState()).toBe(5);
|
expect(reduxStore.getState()).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should bind action creators', async () => {
|
it('Should bind action creators', async () => {
|
||||||
const addTodo = (text) => {
|
const addTodo = text => {
|
||||||
return {
|
return {
|
||||||
type: 'ADD_TODO',
|
type: 'ADD_TODO',
|
||||||
text
|
text,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const reduxStore = createStore((state = [], action) => {
|
const reduxStore = createStore((state = [], action) => {
|
||||||
if (action.type === 'ADD_TODO') {
|
if (action.type === 'ADD_TODO') {
|
||||||
|
@ -74,7 +74,7 @@ describe('Redux adapter', () => {
|
||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
|
|
||||||
const actions = bindActionCreators({addTodo}, reduxStore.dispatch);
|
const actions = bindActionCreators({ addTodo }, reduxStore.dispatch);
|
||||||
|
|
||||||
actions.addTodo('todo');
|
actions.addTodo('todo');
|
||||||
|
|
||||||
|
@ -84,57 +84,57 @@ describe('Redux adapter', () => {
|
||||||
it('Should replace reducer', async () => {
|
it('Should replace reducer', async () => {
|
||||||
const reduxStore = createStore((state, action) => {
|
const reduxStore = createStore((state, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case('ADD'):
|
case 'ADD':
|
||||||
return {counter: state.counter + 1}
|
return { counter: state.counter + 1 };
|
||||||
default:
|
default:
|
||||||
return {counter: 0};
|
return { counter: 0 };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(1);
|
expect(reduxStore.getState().counter).toBe(1);
|
||||||
|
|
||||||
reduxStore.replaceReducer((state, action) => {
|
reduxStore.replaceReducer((state, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case('SUB'):
|
case 'SUB':
|
||||||
return {counter: state.counter - 1}
|
return { counter: state.counter - 1 };
|
||||||
default:
|
default:
|
||||||
return {counter: 0};
|
return { counter: 0 };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'SUB'});
|
reduxStore.dispatch({ type: 'SUB' });
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(0);
|
expect(reduxStore.getState().counter).toBe(0);
|
||||||
})
|
});
|
||||||
|
|
||||||
it('Should combine reducers', async () => {
|
it('Should combine reducers', async () => {
|
||||||
const booleanReducer = (state = false, action) => {
|
const booleanReducer = (state = false, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case('TOGGLE'):
|
case 'TOGGLE':
|
||||||
return !state
|
return !state;
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const addReducer = (state = 0, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case('ADD'):
|
|
||||||
return state + 1
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const reduxStore = createStore(combineReducers({check: booleanReducer, counter: addReducer}));
|
const addReducer = (state = 0, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'ADD':
|
||||||
|
return state + 1;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const reduxStore = createStore(combineReducers({ check: booleanReducer, counter: addReducer }));
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(0);
|
expect(reduxStore.getState().counter).toBe(0);
|
||||||
expect(reduxStore.getState().check).toBe(false);
|
expect(reduxStore.getState().check).toBe(false);
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'ADD'});
|
reduxStore.dispatch({ type: 'ADD' });
|
||||||
reduxStore.dispatch({type: 'TOGGLE'});
|
reduxStore.dispatch({ type: 'TOGGLE' });
|
||||||
|
|
||||||
expect(reduxStore.getState().counter).toBe(1);
|
expect(reduxStore.getState().counter).toBe(1);
|
||||||
expect(reduxStore.getState().check).toBe(true);
|
expect(reduxStore.getState().check).toBe(true);
|
||||||
|
@ -149,21 +149,25 @@ describe('Redux adapter', () => {
|
||||||
counter++;
|
counter++;
|
||||||
let result = next(action);
|
let result = next(action);
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
const reduxStore = createStore((state, action) => {
|
const reduxStore = createStore(
|
||||||
switch (action.type) {
|
(state, action) => {
|
||||||
case('toggle'):
|
switch (action.type) {
|
||||||
return {
|
case 'toggle':
|
||||||
check: !state.check
|
return {
|
||||||
}
|
check: !state.check,
|
||||||
default:
|
};
|
||||||
return state;
|
default:
|
||||||
}
|
return state;
|
||||||
}, {check: false}, applyMiddleware(callCounter));
|
}
|
||||||
|
},
|
||||||
|
{ check: false },
|
||||||
|
applyMiddleware(callCounter)
|
||||||
|
);
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'toggle'});
|
reduxStore.dispatch({ type: 'toggle' });
|
||||||
reduxStore.dispatch({type: 'toggle'});
|
reduxStore.dispatch({ type: 'toggle' });
|
||||||
|
|
||||||
expect(counter).toBe(3); // NOTE: first action is always store initialization
|
expect(counter).toBe(3); // NOTE: first action is always store initialization
|
||||||
});
|
});
|
||||||
|
@ -178,31 +182,35 @@ describe('Redux adapter', () => {
|
||||||
counter++;
|
counter++;
|
||||||
let result = next(action);
|
let result = next(action);
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
const lastFunctionStorage = store => next => action => {
|
const lastFunctionStorage = store => next => action => {
|
||||||
middlewareCallList.push('lastFunctionStorage');
|
middlewareCallList.push('lastFunctionStorage');
|
||||||
lastAction = action.type;
|
lastAction = action.type;
|
||||||
let result = next(action);
|
let result = next(action);
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
const reduxStore = createStore((state, action) => {
|
const reduxStore = createStore(
|
||||||
switch (action.type) {
|
(state, action) => {
|
||||||
case('toggle'):
|
switch (action.type) {
|
||||||
return {
|
case 'toggle':
|
||||||
check: !state.check
|
return {
|
||||||
}
|
check: !state.check,
|
||||||
default:
|
};
|
||||||
return state;
|
default:
|
||||||
}
|
return state;
|
||||||
}, {check: false}, applyMiddleware(callCounter, lastFunctionStorage));
|
}
|
||||||
|
},
|
||||||
|
{ check: false },
|
||||||
|
applyMiddleware(callCounter, lastFunctionStorage)
|
||||||
|
);
|
||||||
|
|
||||||
reduxStore.dispatch({type: 'toggle'});
|
reduxStore.dispatch({ type: 'toggle' });
|
||||||
|
|
||||||
expect(counter).toBe(2); // NOTE: first action is always store initialization
|
expect(counter).toBe(2); // NOTE: first action is always store initialization
|
||||||
expect(lastAction).toBe('toggle');
|
expect(lastAction).toBe('toggle');
|
||||||
expect(middlewareCallList[0]).toBe("callCounter");
|
expect(middlewareCallList[0]).toBe('callCounter');
|
||||||
expect(middlewareCallList[1]).toBe("lastFunctionStorage");
|
expect(middlewareCallList[1]).toBe('lastFunctionStorage');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { unmountComponentAtNode } from '../../../libs/horizon/src/dom/DOMExternal';
|
import { unmountComponentAtNode } from '../../../libs/horizon/src/dom/DOMExternal';
|
||||||
import { getLogUtils } from './testUtils';
|
import { getLogUtils } from './testUtils';
|
||||||
//import failOnConsole from 'jest-fail-on-console';
|
|
||||||
|
|
||||||
//failOnConsole();
|
|
||||||
const LogUtils = getLogUtils();
|
const LogUtils = getLogUtils();
|
||||||
global.isDev = process.env.NODE_ENV === 'development';
|
global.isDev = process.env.NODE_ENV === 'development';
|
||||||
global.isTest = true;
|
global.isTest = true;
|
||||||
|
|
|
@ -1,68 +1,9 @@
|
||||||
import { allDelegatedNativeEvents } from '@cloudsop/horizon/src/event/EventHub';
|
|
||||||
//import * as LogUtils from './logUtils';
|
|
||||||
|
|
||||||
export const stopBubbleOrCapture = (e, value) => {
|
export const stopBubbleOrCapture = (e, value) => {
|
||||||
const LogUtils = getLogUtils();
|
const LogUtils = getLogUtils();
|
||||||
LogUtils.log(value);
|
LogUtils.log(value);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
|
||||||
function listAllEventListeners() {
|
|
||||||
const allElements = Array.prototype.slice.call(document.querySelectorAll('*'));
|
|
||||||
allElements.push(document);
|
|
||||||
allElements.push(window);
|
|
||||||
|
|
||||||
const types = [];
|
|
||||||
|
|
||||||
for (let ev in window) {
|
|
||||||
if (/^on/.test(ev)) types[types.length] = ev;
|
|
||||||
}
|
|
||||||
|
|
||||||
let elements = [];
|
|
||||||
for (let i = 0; i < allElements.length; i++) {
|
|
||||||
const currentElement = allElements[i];
|
|
||||||
for (let j = 0; j < types.length; j++) {
|
|
||||||
if (typeof currentElement[types[j]] === 'function') {
|
|
||||||
elements.push({
|
|
||||||
'node': currentElement,
|
|
||||||
'type': types[j],
|
|
||||||
'func': currentElement[types[j]].toString(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements.sort(function(a,b) {
|
|
||||||
return a.type.localeCompare(b.type);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getEventListeners = (dom) => {
|
|
||||||
console.table(listAllEventListeners());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// let ret = true;
|
|
||||||
// let keyArray = [];
|
|
||||||
// for (let key in dom) {
|
|
||||||
// if (/^on/.test(key)) keyArray.push(key);
|
|
||||||
// }
|
|
||||||
// console.log(getEventListeners);
|
|
||||||
// console.log('---------------------------------');
|
|
||||||
// console.log(allDelegatedNativeEvents);
|
|
||||||
// try {
|
|
||||||
// allDelegatedNativeEvents.forEach(event => {
|
|
||||||
// if (!keyArray.includes(event)) {
|
|
||||||
// ret = false;
|
|
||||||
// throw new Error('没有挂载全量事件');
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// }
|
|
||||||
// return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function triggerClickEvent(container, id) {
|
export function triggerClickEvent(container, id) {
|
||||||
const event = new MouseEvent('click', {
|
const event = new MouseEvent('click', {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
|
|
Loading…
Reference in New Issue