Skip to content

Commit 330ab5c

Browse files
committed
Add compat layer for unit tests, re-enable tests in CI
1 parent 5dcc18f commit 330ab5c

8 files changed

Lines changed: 859 additions & 25 deletions

File tree

.github/workflows/pull_request.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ jobs:
147147
- name: Site lint
148148
run: npm run lint
149149

150-
# TODO: Reinstate tests as part of build
151-
# I am disabling this for now to see how the rest of the build pipeline works
152-
# with the Vue 3 upgrade.
153-
# - name: Run unit tests
154-
# run: npm run test:unit
150+
- name: Run unit tests
151+
run: npm run test:unit
155152

156153
desktop_unit_tests:
157154
name: Desktop unit tests

td.vue/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = async () => {
1010
// TODO: Remove this alias when fully migrated to Vue 3 and
1111
// the compat dependency is removed
1212
'^vue$': require.resolve('@vue/compat'),
13+
'^@vue/test-utils$': '<rootDir>/src/plugins/vue-test-utils-compat.js',
14+
'^vue-i18n$': '<rootDir>/src/plugins/vue-i18n-test-compat.js',
1315
'^@/(.*)$': '<rootDir>/src/$1',
1416
'^lodash-es$': 'lodash'
1517
},
@@ -29,4 +31,3 @@ module.exports = async () => {
2931
]
3032
};
3133
};
32-
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as actual from 'vue-i18n/dist/vue-i18n.cjs';
2+
3+
const installLegacyCompat = (instance) => {
4+
if (typeof instance.t !== 'function' && typeof instance.global?.t === 'function') {
5+
instance.t = instance.global.t.bind(instance.global);
6+
}
7+
8+
if (typeof instance.tc !== 'function' && typeof instance.global?.tc === 'function') {
9+
instance.tc = instance.global.tc.bind(instance.global);
10+
}
11+
12+
if (!Object.getOwnPropertyDescriptor(instance, 'locale') && instance.global) {
13+
Object.defineProperty(instance, 'locale', {
14+
get() {
15+
return instance.global.locale;
16+
},
17+
set(value) {
18+
instance.global.locale = value;
19+
}
20+
});
21+
}
22+
23+
if (!Object.getOwnPropertyDescriptor(instance, 'availableLocales') && instance.global) {
24+
Object.defineProperty(instance, 'availableLocales', {
25+
get() {
26+
return instance.global.availableLocales || [];
27+
}
28+
});
29+
}
30+
31+
return instance;
32+
};
33+
34+
function VueI18n(options = {}) {
35+
return installLegacyCompat(actual.createI18n({
36+
legacy: true,
37+
...options
38+
}));
39+
}
40+
41+
VueI18n.install = () => {};
42+
VueI18n.createI18n = actual.createI18n;
43+
VueI18n.useI18n = actual.useI18n;
44+
45+
export const castToVueI18n = (instance) => installLegacyCompat(actual.castToVueI18n(instance));
46+
export const createI18n = (...args) => installLegacyCompat(actual.createI18n(...args));
47+
48+
export const {
49+
DatetimeFormat,
50+
I18nD,
51+
I18nInjectionKey,
52+
I18nN,
53+
I18nT,
54+
NumberFormat,
55+
Translation,
56+
VERSION,
57+
useI18n,
58+
vTDirective
59+
} = actual;
60+
61+
export default VueI18n;

0 commit comments

Comments
 (0)