Skip to content

Commit

Permalink
updated example to use esm 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kenotron committed Jan 16, 2019
1 parent 7fe0ac9 commit 3be459b
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 293 deletions.
15 changes: 6 additions & 9 deletions SomeComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/*import React from 'react';
import addBar from './index';*/

const React = require('react');
const addBar = require('./index').default;
import React from 'react';
import addBar from './index';

class SomeComponent extends React.Component {
render() {
return React.createElement('div', null, addBar(this.props.value));
}
render() {
return React.createElement('div', null, addBar(this.props.value));
}
}

module.exports.default = SomeComponent;
// export default SomeComponent;
// export default SomeComponent;
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//import * as bar from 'anotherRoot/bar';
const bar = require('anotherRoot/bar');
import bar from 'anotherRoot/bar';

function addBar(y) {
// ESM:
return bar.default() + y;
function addBar(y) {
return bar() + y;
}

//export default addBar;
module.exports.default = addBar;
export default addBar;
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
transform: {
'\\.m?js$': '<rootDir>/node_modules/esm/esm.js'
},
moduleNameMapper: {
'^anotherRoot/(.*)$': '<rootDir>/lib/anotherRoot/$1'
},
transformIgnorePatterns: []
};
5 changes: 0 additions & 5 deletions jestconfig.js

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
{
"name": "esm-jest",
"scripts": {
"test": "node node_modules/jest/bin/jest.js --runInBand --no-cache --config jestconfig.js"
},
"directories": {
"test": "test"
"test": "node -r esm node_modules/jest/bin/jest.js --runInBand --no-cache --config jest.config.js"
},
"dependencies": {
"esm": "3.0.12",
"esm": "3.1.0",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "1.1.1",
"react": "16.3.0",
"react-dom": "16.3.0"
},
"devDependencies": {
"jest": "^22.4.3"
"jest": "^23.6.0"
}
}
23 changes: 6 additions & 17 deletions test/__tests__/SomeComponentTest.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
/*
import React from 'react';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

import { shallow } from 'enzyme';
import SomeComponent from '../../SomeComponent';
import * as bar from 'anotherRoot/bar';
*/

const React = require('react');
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

const shallow = Enzyme.shallow;

const SomeComponent = require('../../SomeComponent').default;
const bar = require('anotherRoot/bar');

Enzyme.configure({ adapter: new Adapter() });

describe('SomeComponent', () => {
it('should test component', () => {
spyOn(bar, 'default').and.returnValue(7);
const wrapper = shallow(React.createElement(SomeComponent, {value: 1}));
expect(wrapper.text()).toBe('8');
});
});
it('should test component', () => {
spyOn(bar, 'default').and.returnValue(7);
const wrapper = shallow(React.createElement(SomeComponent, { value: 1 }));
expect(wrapper.text()).toBe('8');
});
});
12 changes: 3 additions & 9 deletions test/__tests__/test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
/*
import { addBar } from '../../index';
import * as bar from 'anotherRoot/bar';
*/

const bar = require('anotherRoot/bar');
const addBar = require('../../index').default;

test('addBar should be add five', () => {
expect(addBar(2)).toBe(7);
expect(addBar(2)).toBe(7);
});

test('addBar should be add another number', () => {
spyOn(bar, 'default').and.returnValue(6);
expect(addBar(2)).toBe(8);
spyOn(bar, 'default').and.returnValue(6);
expect(addBar(2)).toBe(8);
});

Loading

0 comments on commit 3be459b

Please sign in to comment.