Add a test

master
Vitaliy Filippov 2021-08-28 16:34:45 +03:00
parent 7001bfbc92
commit 14a73ed9df
3 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`works 1`] = `
"import { L } from \\"babel-plugin-react-translate/runtime\\";
var name = \\"John\\";
var foo = L(\\"\\\\u0401-Mobile\\");
foo = L(\\"\\\\u041C\\\\u0435\\\\u043D\\\\u044F \\\\u0437\\\\u043E\\\\u0432\\\\u0443\\\\u0442 {1}!\\", name) + \\" \\";
foo = \\" \\" + L(\\"\\\\u041C\\\\u0435\\\\u043D\\\\u044F \\\\u0437\\\\u043E\\\\u0432\\\\u0443\\\\u0442 {1}!\\", name);
foo = /*#__PURE__*/React.createElement(\\"span\\", null, L(\\"\\\\u041F\\\\u0440\\\\u0438\\\\u0432\\\\u0435\\\\u0442!\\"));
foo = L(\\"У меня много {1}: \\", L(\\"братьев\\"));"
`;

28
__tests__/index-test.js Normal file
View File

@ -0,0 +1,28 @@
const fs = require('fs');
const babel = require('@babel/core');
const jsx = require('@babel/plugin-transform-react-jsx');
const plugin = require('../');
var example = '\
var name = "John";\
var foo = "Ё-Mobile";\
foo = "Меня зовут "+name+"! ";\
foo = ` Меня зовут ${name}!`;\
foo = <span>Привет!</span>;\
foo = L("У меня много {1}: ", L("братьев"));\
';
it('works', () =>
{
const { code } = babel.transform(example, { filename: 'test', plugins: [ jsx, plugin ] });
expect(code).toMatchSnapshot();
expect(JSON.parse(fs.readFileSync('react-translate-output.json'))).toEqual({
test: [
"Ё-Mobile",
"Меня зовут {1}!",
"Привет!",
"У меня много {1}: ",
"братьев",
]
});
});

View File

@ -4,7 +4,7 @@
"description": "Babel-based JS/JSX auto-translator for Russian language",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"repository": {
"type": "git",
@ -27,10 +27,21 @@
"russian",
"translation"
],
"files": [
"index.js",
"plural_ru.js",
"runtime.js",
"COPYING"
],
"author": {
"name": "Vitaliy Filippov",
"email": "vitalif@yourcmc.ru",
"url": "http://yourcmc.ru/wiki/"
},
"license": "LGPL-3.0"
"license": "LGPL-3.0",
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"jest": "^27.1.0"
}
}