From 14a73ed9df96cef8632435313df33fb5622f0d09 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 28 Aug 2021 16:34:45 +0300 Subject: [PATCH] Add a test --- __tests__/__snapshots__/index-test.js.snap | 11 +++++++++ __tests__/index-test.js | 28 ++++++++++++++++++++++ package.json | 15 ++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 __tests__/__snapshots__/index-test.js.snap create mode 100644 __tests__/index-test.js diff --git a/__tests__/__snapshots__/index-test.js.snap b/__tests__/__snapshots__/index-test.js.snap new file mode 100644 index 0000000..160efc7 --- /dev/null +++ b/__tests__/__snapshots__/index-test.js.snap @@ -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(\\"братьев\\"));" +`; diff --git a/__tests__/index-test.js b/__tests__/index-test.js new file mode 100644 index 0000000..43da0eb --- /dev/null +++ b/__tests__/index-test.js @@ -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 = Привет!;\ +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}: ", + "братьев", + ] + }); +}); diff --git a/package.json b/package.json index d18f898..eb0e729 100644 --- a/package.json +++ b/package.json @@ -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" + } }