Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit e491de9

Browse files
authored
Add script to build fixtures (#72)
* Add script to build fixtures * Rebuild fixtures for latest Babel changes
1 parent 01d731e commit e491de9

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"clean": "rimraf lib/",
3535
"test": "cross-env NODE_ENV=test mocha --compilers js:babel-register",
3636
"build": "babel src/ --out-dir lib/",
37+
"build:fixtures": "babel-node ./scripts/build-fixtures.js",
3738
"preversion": "npm run lint && npm run clean && npm run build",
3839
"prepublish": "npm run clean && npm run build"
3940
},

scripts/build-fixtures.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as p from 'path';
2+
import * as fs from 'fs';
3+
import {transformFileSync} from 'babel-core';
4+
import plugin from '../src/index';
5+
6+
const baseDir = p.resolve(`${__dirname}/../test/fixtures`);
7+
8+
const fixtures = [
9+
'defineMessages',
10+
'FormattedHTMLMessage',
11+
'FormattedMessage',
12+
['moduleSourceName', {
13+
moduleSourceName: 'react-i18n',
14+
}],
15+
];
16+
17+
fixtures.forEach((fixture) => {
18+
let name = fixture;
19+
let options = {};
20+
if (Array.isArray(fixture)) {
21+
[name, options] = fixture;
22+
}
23+
24+
let {code, metadata} = transformFileSync(`${baseDir}/${name}/actual.js`, {
25+
plugins: [
26+
[plugin, {
27+
...options,
28+
messagesDir: false,
29+
}],
30+
],
31+
});
32+
33+
let messages = JSON.stringify(metadata['react-intl'].messages, null, 2);
34+
35+
fs.writeFileSync(`${baseDir}/${name}/expected.js`, `${code}\n`);
36+
fs.writeFileSync(`${baseDir}/${name}/expected.json`, `${messages}\n`);
37+
});

test/fixtures/FormattedHTMLMessage/expected.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Foo = function (_Component) {
2626
function Foo() {
2727
_classCallCheck(this, Foo);
2828

29-
return _possibleConstructorReturn(this, Object.getPrototypeOf(Foo).apply(this, arguments));
29+
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
3030
}
3131

3232
_createClass(Foo, [{
@@ -44,4 +44,3 @@ var Foo = function (_Component) {
4444
}(_react.Component);
4545

4646
exports.default = Foo;
47-

test/fixtures/FormattedMessage/expected.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var Foo = function (_Component) {
2626
function Foo() {
2727
_classCallCheck(this, Foo);
2828

29-
return _possibleConstructorReturn(this, Object.getPrototypeOf(Foo).apply(this, arguments));
29+
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
3030
}
3131

3232
_createClass(Foo, [{
@@ -44,4 +44,3 @@ var Foo = function (_Component) {
4444
}(_react.Component);
4545

4646
exports.default = Foo;
47-

test/fixtures/defineMessages/expected.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var Foo = function (_Component) {
3939
function Foo() {
4040
_classCallCheck(this, Foo);
4141

42-
return _possibleConstructorReturn(this, Object.getPrototypeOf(Foo).apply(this, arguments));
42+
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
4343
}
4444

4545
_createClass(Foo, [{
@@ -66,4 +66,3 @@ var Foo = function (_Component) {
6666
}(_react.Component);
6767

6868
exports.default = Foo;
69-

test/fixtures/moduleSourceName/expected.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Foo = function (_Component) {
4343
function Foo() {
4444
_classCallCheck(this, Foo);
4545

46-
return _possibleConstructorReturn(this, Object.getPrototypeOf(Foo).apply(this, arguments));
46+
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
4747
}
4848

4949
_createClass(Foo, [{
@@ -66,4 +66,3 @@ var Foo = function (_Component) {
6666
}(_react.Component);
6767

6868
exports.default = Foo;
69-

0 commit comments

Comments
 (0)