Skip to content

Commit

Permalink
feat(babel): upgrade babel 7 (#10)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Maybe require Babel 7>=
  • Loading branch information
azu authored Sep 16, 2018
1 parent be71b1e commit 889d757
Show file tree
Hide file tree
Showing 39 changed files with 2,046 additions and 68 deletions.
7 changes: 2 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports"
"@babel/preset-env"
]
}
}
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build": "babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build",
"test": "mocha"
"test": "mocha",
"updateSnapshot": "UPDATE_SNAPSHOT=1 mocha"
},
"keywords": [
"babel",
Expand All @@ -31,19 +32,13 @@
"testing",
"coc"
],
"directories": {
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build",
"test": "mocha --compilers js:babel-register"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.18.0",
"mocha": "^3.1.2"
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-plugin-add-module-exports": "^1.0.0",
"mocha": "^5.2.0"
},
"dependencies": {
"doctrine": "^2.0.0",
Expand Down
43 changes: 25 additions & 18 deletions test/babel-plugin-jsdoc-to-assert-test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
const assert = require('assert');
const fs = require('fs');
const path = require('path');
import {transformFileSync} from 'babel-core';
import { transformFileSync } from '@babel/core';

function normalize(str) {
return str.replace(/^\s+|\s+$/, '').replace(/\r?\n/g, '\n');
return str.replace(/^\s+|\s+$/, '').replace(/\r?\n/g, '\n');
}

describe('JSDoc plugin', () => {
const fixturesDir = path.join(__dirname, 'fixtures');
fs.readdirSync(fixturesDir).map((caseName) => {
it(`should generate assertions for ${caseName.replace(/-/g, ' ')}`, () => {
const fixtureDir = path.join(fixturesDir, caseName);
let actualPath = path.join(fixtureDir, 'actual.js');
const actual = transformFileSync(actualPath).code;
const fixturesDir = path.join(__dirname, 'fixtures');
fs.readdirSync(fixturesDir).map((caseName) => {
it(`should generate assertions for ${caseName.replace(/-/g, ' ')}`, function() {
const fixtureDir = path.join(fixturesDir, caseName);
let actualPath = path.join(fixtureDir, 'actual.js');
const actual = transformFileSync(actualPath).code;

if (path.sep === '\\') {
// Specific case of windows, transformFileSync return code with '/'
actualPath = actualPath.replace(/\\/g, '/');
}
if (path.sep === '\\') {
// Specific case of windows, transformFileSync return code with '/'
actualPath = actualPath.replace(/\\/g, '/');
}

const expected = fs.readFileSync(
path.join(fixtureDir, 'expected.js')
).toString().replace(/%FIXTURE_PATH%/g, actualPath);
const expectedPath = path.join(fixtureDir, 'expected.js');
const expected = fs.readFileSync(
expectedPath
).toString().replace(/%FIXTURE_PATH%/g, actualPath);

assert.equal(normalize(actual), normalize(expected));
});
// UPDATE_SNAPSHOT=1 npm test で呼び出したときはスナップショットを更新
if (process.env.UPDATE_SNAPSHOT) {
fs.writeFileSync(expectedPath, actual);
this.skip(); // スキップ
return;
}
assert.equal(normalize(actual), normalize(expected));
});
});
});
});
2 changes: 1 addition & 1 deletion test/fixtures/ArrowFunctionExpression/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/AssertOption/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/ClassMethod/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/ClassMethod/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ class X {
console.assert(typeof x === "number");
console.assert(typeof y === "string");
}

}
3 changes: 1 addition & 2 deletions test/fixtures/Default-Option-Generator/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"plugins": [
"../../../src/"
// use spec generator
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/ExportDefaultFunctionDeclaration/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/ExportDefaultFunctionDestructuring/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
4 changes: 3 additions & 1 deletion test/fixtures/ExportDefaultFunctionDestructuring/expected.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* @param {string} key
*/
export default function fn({ key }) {
export default function fn({
key
}) {
console.assert(typeof key === "string");
}
2 changes: 1 addition & 1 deletion test/fixtures/ExportFunctionDeclaration/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/FunctionDeclaration/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/FunctionExpression/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
1 change: 0 additions & 1 deletion test/fixtures/FunctionExpression/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const obj = {
*/
log: function (message) {
console.assert(typeof message === "string");

console.log(message);
}
};
2 changes: 1 addition & 1 deletion test/fixtures/NOT_SUPPORT_Type_Object/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/NOT_SUPPORT_Type_Object/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ const obj = {
* @type {string}
*/
value: "s"
};
};
2 changes: 1 addition & 1 deletion test/fixtures/NoTypeOption/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/ObjectMethod/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
3 changes: 2 additions & 1 deletion test/fixtures/ObjectMethod/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ var object = {
console.assert(typeof x === "number");
console.assert(typeof y === "string");
}
};

};
2 changes: 1 addition & 1 deletion test/fixtures/ObjectMethodB/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/ObjectMethodB/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ const cli = {
return typeof item === "string";
}));
}

};
4 changes: 2 additions & 2 deletions test/fixtures/ObjectMethod_with_es2015/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
"es2015"
"@babel/preset-env"
],
"plugins": [
[
Expand All @@ -10,4 +10,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/SpecGenerator-param/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/SpecGenerator-type/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
}
]
]
}
}
3 changes: 2 additions & 1 deletion test/fixtures/SpecGenerator-type/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const value = "s";
/**
* @type {string[]}
*/

console.assert(typeof value === "string", 'Expected type: @type {string} value\nActual value:', value, '\nFailure assertion: typeof value === "string"');
const array = ["s"];
console.assert(Array.isArray(array) && array.every(function (item) {
return typeof item === "string";
}), 'Expected type: @type {Array.<string>} array\nActual value:', array, '\nFailure assertion: Array.isArray(array) && array.every(function(item){ return (typeof item === "string"); })');
}), 'Expected type: @type {Array.<string>} array\nActual value:', array, '\nFailure assertion: Array.isArray(array) && array.every(function(item){ return (typeof item === "string"); })');
2 changes: 1 addition & 1 deletion test/fixtures/TypeCustomObject/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/TypeExportExpression/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/TypeExportExpression/expected.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
* @type {string}
*/
export const ItemType = 'ItemType';
export const ItemType = 'ItemType';
2 changes: 1 addition & 1 deletion test/fixtures/TypeString/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/TypeThisAssignMent/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/TypeThisAssignMent/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class A {
this.value = "s";
console.assert(typeof this.value === "string");
}

}
2 changes: 1 addition & 1 deletion test/fixtures/TypeVariableAssignMent/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/TypeVariableAssignMent/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ var value;
/**
* @type {string}
*/

value = "s";
console.assert(typeof value === "string");
2 changes: 1 addition & 1 deletion test/fixtures/VariableDeclaration/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
2 changes: 1 addition & 1 deletion test/fixtures/multiple-comments/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
}
]
]
}
}
1 change: 1 addition & 0 deletions test/fixtures/multiple-comments/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @typedef {Object} O
* @property {number} x - this is a param.
*/

/**
* @param {number} param - this is a param.
* @param {string} b - this is a param.
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--compilers js:babel-register
--require @babel/register
Loading

0 comments on commit 889d757

Please sign in to comment.