|
| 1 | +/** |
| 2 | + * This script file presents you the opportunity of running some code immediately |
| 3 | + * after the test framework has been installed in the environment. |
| 4 | + */ |
| 5 | +import {HyperFormula} from '../../src' |
| 6 | +import {Config} from '../../src/Config' |
| 7 | +import {enGB} from '../../src/i18n/languages' |
| 8 | +import * as plugins from '../../src/interpreter/plugin' |
| 9 | +import {toContainEqualMatcher, toEqualErrorMatcher, toMatchObjectMatcher} from './matchers' |
| 10 | + |
| 11 | +function unregisterAllLanguages() { |
| 12 | + for (const langCode of HyperFormula.getRegisteredLanguagesCodes()) { |
| 13 | + HyperFormula.unregisterLanguage(langCode) |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +Config.defaultConfig = Object.assign({}, Config.defaultConfig, { |
| 18 | + functionPlugins: [], |
| 19 | + useStats: true, |
| 20 | + licenseKey: 'gpl-v3', |
| 21 | +}) |
| 22 | + |
| 23 | +const jestPresent = (() => { |
| 24 | + try { |
| 25 | + expect([{a: 0}]).toContainEqual({a: 0}) |
| 26 | + return true |
| 27 | + } catch (e) { |
| 28 | + return false |
| 29 | + } |
| 30 | +})() |
| 31 | + |
| 32 | +beforeEach(() => { |
| 33 | + if (!jestPresent) { |
| 34 | + (jasmine as any).setDefaultSpyStrategy((and: any) => and.callThrough()) |
| 35 | + } |
| 36 | + |
| 37 | + unregisterAllLanguages() |
| 38 | + |
| 39 | + const defaultLanguage = Config.defaultConfig.language |
| 40 | + |
| 41 | + HyperFormula.registerLanguage(defaultLanguage, enGB) |
| 42 | + |
| 43 | + HyperFormula.unregisterAllFunctions() |
| 44 | + |
| 45 | + for (const pluginName of Object.getOwnPropertyNames(plugins)) { |
| 46 | + if (!pluginName.startsWith('_')) { |
| 47 | + HyperFormula.registerFunctionPlugin(plugins[pluginName as keyof typeof plugins]) |
| 48 | + } |
| 49 | + } |
| 50 | +}) |
| 51 | + |
| 52 | +beforeAll(() => { |
| 53 | + if (!jestPresent) { |
| 54 | + (jasmine as any).addMatchers({ |
| 55 | + ...toContainEqualMatcher, |
| 56 | + ...toMatchObjectMatcher, |
| 57 | + ...toEqualErrorMatcher, |
| 58 | + }) |
| 59 | + } else { |
| 60 | + if (global.gc) { |
| 61 | + global.gc() |
| 62 | + } |
| 63 | + } |
| 64 | +}) |
0 commit comments