-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Revert vueOptionsNamespace changes from <script setup> commit (#501
) * chore: Remove this. in <template> in test Signed-off-by: Wolfgang Walther <walther@technowledgy.de> * test: Add custom-block test for 2.x package Signed-off-by: Wolfgang Walther <walther@technowledgy.de> * fix: Revert vueOptionsNamespace changes from <script setup> commit Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
- Loading branch information
1 parent
857f1a8
commit af89526
Showing
10 changed files
with
179 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Basic 1`] = ` | ||
[ | ||
{ | ||
"en": { | ||
"hello": "Hello!", | ||
}, | ||
"ja": { | ||
"hello": "こんにちは!", | ||
}, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Multiple blocks 1`] = ` | ||
[ | ||
{ | ||
"en": { | ||
"hello": "Hello!", | ||
}, | ||
"ja": { | ||
"hello": "こんにちは!", | ||
}, | ||
}, | ||
{ | ||
"foo": "foo", | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<p>basic custom block</p> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Basic' | ||
} | ||
</script> | ||
|
||
<custom> | ||
{ | ||
"en": { | ||
"hello": "Hello!" | ||
}, | ||
"ja": { | ||
"hello": "こんにちは!" | ||
} | ||
} | ||
</custom> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<p>multiple custom block</p> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Multiple' | ||
} | ||
</script> | ||
|
||
<custom> | ||
{ | ||
"en": { | ||
"hello": "Hello!" | ||
}, | ||
"ja": { | ||
"hello": "こんにちは!" | ||
} | ||
} | ||
</custom> | ||
|
||
<custom> | ||
{ | ||
"foo": "foo" | ||
} | ||
</custom> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "vue2-custom-block", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"test": "jest --no-cache --coverage test.js" | ||
}, | ||
"dependencies": { | ||
"vue": "^2.7.7", | ||
"vue-template-compiler": "^2.7.7" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
"@vue/vue2-jest": "^29.0.0", | ||
"jest": "29.x", | ||
"jest-environment-jsdom": "29.x" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"vue" | ||
], | ||
"transform": { | ||
"^.+\\.js$": "babel-jest", | ||
"^.+\\.vue$": "@vue/vue2-jest" | ||
}, | ||
"moduleNameMapper": { | ||
"^~?__styles/(.*)$": "<rootDir>/components/styles/$1" | ||
}, | ||
"globals": { | ||
"vue-jest": { | ||
"transform": { | ||
"custom": "./transformer.js" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Basic from './components/Basic.vue' | ||
import Multiple from './components/Multiple.vue' | ||
|
||
test('Basic', () => { | ||
expect(Basic.__custom).toMatchObject([ | ||
{ | ||
en: { | ||
hello: 'Hello!' | ||
}, | ||
ja: { | ||
hello: 'こんにちは!' | ||
} | ||
} | ||
]) | ||
expect(Basic.__custom).toMatchSnapshot() | ||
}) | ||
|
||
test('Multiple blocks', () => { | ||
expect(Multiple.__custom).toMatchObject([ | ||
{ | ||
en: { | ||
hello: 'Hello!' | ||
}, | ||
ja: { | ||
hello: 'こんにちは!' | ||
} | ||
}, | ||
{ | ||
foo: 'foo' | ||
} | ||
]) | ||
expect(Multiple.__custom).toMatchSnapshot() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function convert(content) { | ||
return JSON.stringify(JSON.parse(content)) | ||
.replace(/\u2028/g, '\\u2028') // LINE SEPARATOR | ||
.replace(/\u2029/g, '\\u2029') // PARAGRAPH SEPARATOR | ||
.replace(/\\/g, '\\\\') | ||
.replace(/'/g, "\\'") | ||
} | ||
|
||
module.exports = { | ||
process({ blocks, vueOptionsNamespace, filename, config }) { | ||
const ret = blocks.reduce((codes, block) => { | ||
codes.push( | ||
`${vueOptionsNamespace}.__custom = ${vueOptionsNamespace}.__custom || [];${vueOptionsNamespace}.__custom.push(${convert( | ||
block.content | ||
)});` | ||
) | ||
return codes | ||
}, []) | ||
return ret.join('') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters