Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit dee2464

Browse files
authored
fix: update i18n plugin to work (#352)
1 parent 604edfa commit dee2464

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ Spec | Description
596596
<!-- prettier-ignore-start -->
597597
Spec | Description
598598
--- | ---
599+
[i18n](cypress/component/advanced/i18n) | Testing component that uses [Vue I18n](https://kazupon.github.io/vue-i18n/) plugin
599600
[mocking-axios](cypress/component/advanced/mocking-axios) | Mocking 3rd party module imports, like `axios` for fetching data
600601
[mocking-components](cypress/component/advanced/mocking-components) | Mocking locally registered child components during tests
601602
[mocking-imports](cypress/component/advanced/mocking-imports) | Stub ES6 imports from the tests
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# i18n example
2+
3+
Using [vue-i18n](https://kazupon.github.io/vue-i18n/) and [@intlify/vue-i18n-loader](https://github.com/intlify/vue-i18n-loader/tree/master) stable.
4+
5+
See [TranslatedMessage.vue](TranslatedMessage.vue) and its test in [spec.js](spec.js)
6+
7+
![i18n test in action](./images/i18n.gif)
8+
9+
**Note:** the `vue-i18n-loader` requires a webpack rule, see Webpack config in the root folder.

cypress/component/basic/TranslatedMessage.vue renamed to cypress/component/advanced/i18n/TranslatedMessage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- uses special loader to load i18n blocks -->
2-
<!-- see http://kazupon.github.io/vue-i18n/en/sfc.html -->
2+
<!-- see https://github.com/intlify/vue-i18n-loader -->
33
<i18n>
44
{
55
"en": {
4.88 MB
Loading

cypress/component/basic/translated-message-spec.js renamed to cypress/component/advanced/i18n/spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/// <reference types="cypress" />
22

3-
// testing i18n component
4-
// http://kazupon.github.io/vue-i18n
53
import TranslatedMessage from './TranslatedMessage.vue'
64
import VueI18n from 'vue-i18n'
75
import { mountCallback } from 'cypress-vue-unit-test'
86

9-
// https://github.com/bahmutov/cypress-vue-unit-test/issues/332
10-
describe.skip('VueI18n', () => {
7+
describe('VueI18n', () => {
118
// need to use VueI18n as a plugin
129
const extensions = {
1310
plugins: [VueI18n],
@@ -24,16 +21,17 @@ describe.skip('VueI18n', () => {
2421
cy.viewport(400, 200)
2522

2623
cy.get('select').select('en').should('have.value', 'en')
27-
cy.contains('message: hello')
24+
// wait for good demo movie
25+
cy.contains('message: hello').wait(1000)
2826

2927
cy.get('select').select('fa').should('have.value', 'fa')
30-
cy.contains('message: سلام دنیا')
28+
cy.contains('message: سلام دنیا').wait(1000)
3129

3230
cy.get('select').select('ja').should('have.value', 'ja')
33-
cy.contains('message: こんにちは、世界')
31+
cy.contains('message: こんにちは、世界').wait(1000)
3432

3533
cy.get('select').select('ru').should('have.value', 'ru')
36-
cy.contains('message: Привет мир')
34+
cy.contains('message: Привет мир').wait(1000)
3735
})
3836

3937
// TODO how to load messages not from i18n block but from external JSON file?

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"@babel/plugin-transform-modules-commonjs": "7.10.4",
8989
"@cypress/code-coverage": "3.8.1",
9090
"@cypress/webpack-preprocessor": "5.4.1",
91-
"@kazupon/vue-i18n-loader": "0.5.0",
91+
"@intlify/vue-i18n-loader": "1.0.0",
9292
"babel-plugin-istanbul": "6.0.0",
9393
"common-tags": "1.8.0",
9494
"debug": "4.1.1",

webpack.config.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ module.exports = {
1616
{
1717
test: /\.vue$/,
1818
loader: 'vue-loader',
19-
options: {
20-
loaders: {
21-
// you need to specify `i18n` loaders key with
22-
// `vue-i18n-loader` (https://github.com/kazupon/vue-i18n-loader)
23-
i18n: '@kazupon/vue-i18n-loader',
24-
},
25-
},
2619
},
2720
// this will apply to both plain `.css` files
2821
// AND `<style>` blocks in `.vue` files
2922
{
3023
test: /\.css$/,
3124
use: ['vue-style-loader', 'css-loader'],
3225
},
26+
// https://github.com/intlify/vue-i18n-loader
27+
{
28+
resourceQuery: /blockType=i18n/,
29+
type: 'javascript/auto',
30+
loader: '@intlify/vue-i18n-loader',
31+
},
3332
],
3433
},
3534
plugins: [

0 commit comments

Comments
 (0)