Skip to content

Commit

Permalink
(feature): convert to esm module
Browse files Browse the repository at this point in the history
* Change require by import
* Fix jest configuration for esm module
  • Loading branch information
JuanMaRuiz committed Sep 6, 2021
1 parent 670529c commit adb32ee
Show file tree
Hide file tree
Showing 10 changed files with 3,815 additions and 206 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 8,
"sourceType": "module"
},
"env": {
"node": true,
Expand Down
6 changes: 3 additions & 3 deletions __test__/generator.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const generator = require('./../src/generator.js');
const validator = require('./../src/validator.js');
import generator from './../src/generator.js';
import validate from './../src/validator.js';

test('should return a valid isbn according with the passed param', () => {
const validIsbn = generator('10');
expect(validator(validIsbn)).toBe(true);
expect(validate(validIsbn)).toBe(true);
});

test('should return a isbn string with the correct length depending on when "title" attribute is not passed', () => {
Expand Down
34 changes: 17 additions & 17 deletions __test__/validator.test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
const validator = require('./../src/validator');
import validate from './../src/validator.js';

// Valid ISBN 8497364678, 84-481-2231-3, 978-84-415-2682-2

test('validator should return TRUE if passed value is a valid 10 numbers ISBN ', () => {
expect(validator('84 - 481 - 2231 - 3')).toBe(true);
expect(validator('84 - 481 2231- 3')).toBe(true);
expect(validator('84 481 2231 3')).toBe(true);
expect(validator('8448122313')).toBe(true);
expect(validator('84-481-2231-3')).toBe(true);
expect(validator('006095485X')).toBe(true);
test('validate method should return TRUE if passed value is a valid 10 numbers ISBN ', () => {
expect(validate('84 - 481 - 2231 - 3')).toBe(true);
expect(validate('84 - 481 2231- 3')).toBe(true);
expect(validate('84 481 2231 3')).toBe(true);
expect(validate('8448122313')).toBe(true);
expect(validate('84-481-2231-3')).toBe(true);
expect(validate('006095485X')).toBe(true);
});

test('should return FALSE if passed string does not have the correct lenght', () => {
expect(validator('84 - 481 - 2231')).toBe(false);
expect(validator('848122313')).toBe(false);
expect(validator('isbn: 84-481-2231-3')).toBe(false);
test('validate method should return FALSE if passed string does not have the correct lenght', () => {
expect(validate('84 - 481 - 2231')).toBe(false);
expect(validate('848122313')).toBe(false);
expect(validate('isbn: 84-481-2231-3')).toBe(false);
});

test('validator should return TRUE if passed value is a valid 13 numbers ISBN ', () => {
expect(validator('978-84-415-2682-2')).toBe(true);
expect(validator('978-34-2628-155-0')).toBe(true);
test('validate method should return TRUE if passed value is a valid 13 numbers ISBN ', () => {
expect(validate('978-84-415-2682-2')).toBe(true);
expect(validate('978-34-2628-155-0')).toBe(true);
});

test('validator should return FALSE if passed value is NOT a valid 13 numbers ISBN ', () => {
expect(validator('978-0-306-40615-6')).toBe(false);
test('validate method should return FALSE if passed value is NOT a valid 13 numbers ISBN ', () => {
expect(validate('978-0-306-40615-6')).toBe(false);
});
5 changes: 5 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const validate = require('./src/validator.js');
const generate = require('./src/generator.js');
import validate from './src/validator.js';
import generate from './src/generator.js';

module.exports = {
validate,
generate
};
export { validate, generate };
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
export default {
// All imported modules in your tests should be mocked automatically
// automock: false,

Expand Down Expand Up @@ -170,7 +170,9 @@ module.exports = {
// timers: "real",

// A map from regular expressions to paths to transformers
// transform: undefined,
transform: {
"^.+\\.[t|j]sx?$": "babel-jest"
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
Expand Down
Loading

0 comments on commit adb32ee

Please sign in to comment.