Skip to content

Commit

Permalink
chore(Test): add travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Nov 23, 2018
1 parent 3688ef0 commit 130c4f0
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .fusion
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"engine": "sass",
"publish-template": "@alifd/[email protected].0",
"publish-template": "@alifd/[email protected].x",
"class-prefix": ".next",
"icon": {
"iconfont-project-id": "544230",
Expand Down
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sudo: required

language: node_js

node_js:
- 8

install:
- npm install
- npm install -g codecov

before_script:
- npm i -g npm

script:
- npm run eslint
- npm run stylelint
- npm test
- codecov
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

[![npm package](https://img.shields.io/npm/v/@alifd/next.svg?style=flat-square)](https://www.npmjs.org/package/@alifd/next)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Build Status](https://travis-ci.com/alibaba-fusion/next.svg?token=KAYresHL1UPaaLzUYyx6&branch=master)](https://travis-ci.com/alibaba-fusion/next)
[![codecov](https://codecov.io/gh/alibaba-fusion/next/branch/master/graph/badge.svg?token=FSufKVDhmT)](https://codecov.io/gh/alibaba-fusion/next)

- [Quick Start](./site/en-us/quick-start.md)
- [Use with Theme Package](./site/en-us/theme.md)
Expand Down
2 changes: 2 additions & 0 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

[![npm package](https://img.shields.io/npm/v/@alifd/next.svg?style=flat-square)](https://www.npmjs.org/package/@alifd/next)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Build Status](https://travis-ci.com/alibaba-fusion/next.svg?token=KAYresHL1UPaaLzUYyx6&branch=master)](https://travis-ci.com/alibaba-fusion/next)
[![codecov](https://codecov.io/gh/alibaba-fusion/next/branch/master/graph/badge.svg?token=FSufKVDhmT)](https://codecov.io/gh/alibaba-fusion/next)

- [快速开始](./site/zh-cn/quick-start.md)
- [使用主题包](./site/zh-cn/theme.md)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
"url": "https://github.com/alibaba-fusion/next.git"
},
"scripts": {
"report-coverage": "codecov",
"dev": "node ./scripts/server/index.js",
"build": "node ./scripts/build/index.js",
"check": "node ./scripts/check/index.js",
"docs": "node ./scripts/docs/index.js",
"api": "node ./scripts/api.js",
"pack": "node ./scripts/pack.js",
"release": "node ./scripts/release/index.js",
"test": "node --max_old_space_size=4096 ./scripts/test/index.js",
"test": "node --max_old_space_size=8192 ./scripts/test/index.js",
"order-var": "node ./scripts/order-var.js",
"eslint": "eslint --fix '@(src|scripts)/**/*.@(js|jsx)' && eslint --fix 'docs/**/@(demo|theme)/*.@(md)'",
"stylelint": "stylelint --fix 'src/**/*.@(css|scss)'",
Expand Down Expand Up @@ -86,6 +87,7 @@
"chokidar": "^2.0.4",
"chrome-launcher": "^0.10.2",
"co": "^4.6.0",
"inquirer": "^6.1.0",
"console-polyfill": "^0.3.0",
"conventional-changelog": "^2.0.1",
"css-loader": "^0.28.7",
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function* publishToNpm() {
yield runCommond(`git push origin ${masterTag}`);

yield runCommond('npm publish');
// yield triggerRelease();
yield triggerRelease();
}

function* getGithubInfo() {
Expand Down
92 changes: 71 additions & 21 deletions scripts/test/index.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,102 @@
const cp = require('child_process');
const fs = require('fs-extra');
const { join } = require('path');
const { Server } = require('karma');
const Mocha = require('mocha');
const co = require('co');
const inquirer = require('inquirer');
const { logger, checkComponentName } = require('../utils');

const componentName = checkComponentName(true);
let server = null;
let failedNum = 0, successNum = 0;

const componentName = checkComponentName(true);
const config = {
configFile: join(__dirname, 'karma.js'),
component: componentName,
runAll: false
};

if (componentName === 'all') {
logger.info('Now run all components tests. (You can test one compoent by: npm run test -- number-picker');
}

const coreTest = (cb) => {
const worker = cp.spawn('mocha', [ join('test', 'core'), '--inline-diffs' ]);
worker.stdout.on('data', data => {
logger.info(data.toString());
});
const mocha = new Mocha();
mocha.addFile(join('test', 'core'));

worker.stderr.on('data', data => {
logger.warn(data.toString());
mocha.run(failures => {
failedNum += failures;
typeof cb === 'function' && cb();
});
};

worker.on('close', code => {
typeof cb === 'function' && cb(code);
});
const runRest = components => {
if (components && components.length > 0) {
const com = components.shift();
if (com === 'core') {
coreTest(() => {
runRest(components);
});
return;
}
config.component = com;
config.runAll = true;

server = new Server(config, () => {
server = null;
});
server.start();

server.on('run_complete', (brower, result) => {
const {error, failed, success, exitCode} = result;
failedNum += failed;
successNum += success;
if (error) {
process.exit(exitCode);
} else {
runRest(components);
}
});
} else if (failedNum) {
logger.error(`TOTAL: ${failedNum} FAILED, ${successNum} SUCCESS`);
process.exit(1);
} else {
logger.success('Run all successfully!');
process.exit(0);
}

};

const runAllTest = () => {
const components = fs.readdirSync(join(process.cwd(), 'test'));
runRest(components);
};


switch (componentName) {
case 'core':
coreTest();
break;
case 'all':
config.runAll = true;
server = new Server(config);
co(function* () {
if (process.env.TRAVIS) {
runAllTest();
} else {
const allTest = yield inquirer.prompt([{
name: 'runAllTest',
type: 'list',
choices: ['yes', 'no'],
default: 1,
message: logger.success('This will run ALL components test cases, are you sure to run all?')
}]);

coreTest(() => {
server.start();
if (allTest.runAllTest === 'no') {
logger.success('quit');
return;
} else {
runAllTest();
}
}
});

break;
default:
server = new Server(config);
server.start();
break;
}

37 changes: 18 additions & 19 deletions scripts/test/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ const _ = require('lodash');
const getWebpackConfig = require('./webpack');

module.exports = function(config) {

const { runAll } = config;
const componentName = config.component ? _.kebabCase(config.component) : config.component;
const testDir = `test/${componentName}`;
const runAll = config.runAll;
const singleRun = runAll;
const coveragePath = runAll ? resolveCwd('coverage') : resolveCwd(testDir, 'coverage');
const specPath = runAll ? resolveCwd('test', '**/*-spec.js') : resolveCwd(testDir, '**/*-spec.js');
const coveragePath = resolveCwd('coverage');
const specPath = resolveCwd(testDir, '**/*-spec.js');

const options = {
frameworks: ['mocha'],
browsers: ['Chrome'],
customLaunchers: {
ChromeTravis: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
reporters: ['spec', 'coverage'],
preprocessors: {
[specPath]: ['webpack', 'sourcemap'],
Expand All @@ -25,9 +30,8 @@ module.exports = function(config) {
require.resolve('es5-shim/es5-shim.js'),
require.resolve('es5-shim/es5-sham.js'),
require.resolve('html5shiv/dist/html5shiv.js'),
specPath,
specPath
],

coverageReporter: {
dir: coveragePath,
reporters: [
Expand All @@ -37,29 +41,21 @@ module.exports = function(config) {
},
client: {
mocha: {
timeout: 0,
timeout: 4000,
reporter: 'html',
ui: 'bdd'
}
},
hostname: 'localhost',
browserNoActivityTimeout: 300000,
port: 9876,
browserNoActivityTimeout: 100000,
port: 9877,
colors: true,
autoWatch: true,
autoWatch: !singleRun,
singleRun: singleRun,
concurrency: Infinity,
webpack: getWebpackConfig(componentName, runAll),
webpackMiddleware: {
stats: {
assets: false,
chunks: false,
modules: false,
hash: false,
timings: false,
usedExports: false,
version: false
}
stats: 'errors-only'
},
plugins: [
'karma-chrome-launcher',
Expand All @@ -71,6 +67,9 @@ module.exports = function(config) {
]
};

if (process.env.TRAVIS) {
options.browsers = ['ChromeTravis'];
}
config.set(options);
};

Expand Down
4 changes: 2 additions & 2 deletions scripts/test/webpack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const getWebpackConfig = require('../webpack/dev');

module.exports = function(componentName, runAll) {
const config = getWebpackConfig();
const config = getWebpackConfig(false);

if (runAll || componentName === 'core') {
config.devtool = false;
Expand All @@ -11,7 +11,7 @@ module.exports = function(componentName, runAll) {
config.module.rules = config.module.rules.map(rule => {
if (rule.use.loader === 'babel-loader') {
rule.use.options.plugins.push(
componentName && componentName !== 'all' ? [require.resolve('babel-plugin-istanbul'), {
componentName ? [require.resolve('babel-plugin-istanbul'), {
exclude: [`src/!(${componentName})/**/*.@(js|jsx)`, 'test/**']
}] : require.resolve('babel-plugin-istanbul'),
require.resolve('babel-plugin-espower')
Expand Down
29 changes: 21 additions & 8 deletions scripts/utils/check-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@ const fs = require('fs');
const path = require('path');
const logger = require('./logger');

module.exports = function (allowAll = false) {
const cwd = process.cwd();

module.exports = function (runtest = false) {
const argv = require('minimist')(process.argv.slice(2));

let componentName = argv._[0];
if (componentName) {
// compatible with npm run dev -- Menu
// compatible with npm run dev -- Menu
componentName = _.kebabCase(componentName);
const componentPath = path.join(process.cwd(), 'docs', componentName);
const file = runtest ? 'test' : 'docs';
// const componentPath = path.join(cwd, file, componentName);
const components = fs.readdirSync(path.join(cwd, file));
let name = componentName;
const valid = components.some((com) => {
if (componentName.replace('-', '') === com.replace('-', '')) {
name = com;
return true;
} else {
return false;
}
});

if (!fs.existsSync(componentPath)) {
logger.error(`The input component name (${componentName}) is invalid, try again like: npm run [command] -- number-picker`);
if (!valid) {
logger.error(`The input component name (${componentName}) is invalid, try again like: npm run [command] number-picker`);
process.exit(0);
return false;
}
return componentName;
return name;

} else if (allowAll) {
} else if (runtest) {
return 'all';
} else {
logger.error('Please input the component name, like: npm run [command] -- number-picker');
logger.error('Please input the component name, like: npm run [command] number-picker');
process.exit(0);
return false;
}
Expand Down
16 changes: 11 additions & 5 deletions scripts/webpack/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
const babelConfig = require('@alifd/babel-preset-next')({ modules: false });
const loaders = require('./loaders');

module.exports = function() {
return {
module.exports = function(progress = true) {
const conf = {
output: {
filename: '[name].js'
},
Expand All @@ -28,11 +28,17 @@ module.exports = function() {
}]
},
plugins: [
new webpack.NamedModulesPlugin(),
new CaseSensitivePathsPlugin(),
new WatchMissingNodeModulesPlugin(path.resolve(process.cwd(), 'node_modules')),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.ProgressPlugin()
new webpack.optimize.ModuleConcatenationPlugin()
]
};

if (progress) {
conf.plugins.concat([
new webpack.ProgressPlugin(),
new webpack.NamedModulesPlugin()
]);
}
return conf;
};
Loading

0 comments on commit 130c4f0

Please sign in to comment.