Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smoke tests and harness #352

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[submodule "scripts/react"]
path = scripts/react
url = https://github.com/facebook/react
[submodule "scripts/immutable-js"]
path = scripts/immutable-js
url = https://github.com/facebook/immutable-js
[submodule "scripts/jquery"]
path = scripts/jquery
url = https://github.com/jquery/jquery
[submodule "scripts/draft-js"]
path = scripts/draft-js
url = https://github.com/facebook/draft-js
[submodule "scripts/html-minifier"]
path = scripts/html-minifier
url = https://github.com/kangax/html-minifier
[submodule "scripts/babel"]
path = scripts/babel
url = https://github.com/babel/babel
[submodule "scripts/stylelint"]
path = scripts/stylelint
url = https://github.com/stylelint/stylelint
1 change: 1 addition & 0 deletions scripts/babel
Submodule babel added at ce0c62
1 change: 1 addition & 0 deletions scripts/draft-js
Submodule draft-js added at 437410
1 change: 1 addition & 0 deletions scripts/html-minifier
Submodule html-minifier added at 641901
1 change: 1 addition & 0 deletions scripts/immutable-js
Submodule immutable-js added at 9fcd9f
1 change: 1 addition & 0 deletions scripts/jquery
Submodule jquery added at bf3a43
1 change: 1 addition & 0 deletions scripts/react
Submodule react added at b49210
127 changes: 127 additions & 0 deletions scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
const exec = require("child_process").exec;
const fs = require("fs");
const transform = require("babel-core").transform;
const chalk = require("chalk");
const glob = require("glob");

module.exports = function smoke(options, done) {

// clone options not to mutate them
options = Object.assign({}, options);

let _es2015 = true;

if (options.build) {
options.build = `cd ${options.dir} && ${options.build}`;
}

options.test = `cd ${options.dir} && ${options.test}`;

console.log(chalk.green("1.", options.build || "Nothing to build"));

if (options.build) {
const buildProcess = exec(options.build, (err) => {
if (err) {
console.error(`Error building: ${err}`);
return;
}
minifyAll();
});

options.verbose && buildProcess.stdout.pipe(process.stdout);
}
else {
minifyAll();
}

function minifyAll() {
const globOptions = {
ignore: options.ignore
};
glob(`${options.dir}/${options.files}`, globOptions, (err, files) => {
if (err) {
console.log(`Error getting file(s) path: ${err}`);
return;
}
(function process(file) {
minify(file, _es2015, () => {
const file = files.pop();
if (file) {
process(file);
}
else {
test();
}
});
})(files.pop());
});
}

function minify(file, es2015, done) {
fs.readFile(file, (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
return;
}

console.log(chalk.green(`2. Minifying ${file}, es2015=${es2015}`));

const presets = [
"react",
["babili", options.babiliOptions],
];

if (es2015) {
presets.unshift("es2015");
}

const babelOptions = Object.assign(options.babelOptions || { }, {
comments: false,
minified: true,
passPerPreset: true,
presets,
});

const { code: minified } = transform(data.toString(), babelOptions);

fs.writeFile(file, minified, (err) => {
if (err) {
console.error(`Error writing file: ${err}`);
return;
}
done();
});
});
}

function test() {
console.log(chalk.green("3.", options.test));
const testProcess = exec(options.test, (err, stdout) => {

if (err) {
console.error(`Error testing: ${err}`);
return;
}

const isSuccessful = (
options.success &&
stdout.indexOf(options.success) > -1
);

if (isSuccessful) {
console.log(chalk.black.bgGreen("Success!"));
}

// this is brittle but for now... whatever
if (_es2015) {
_es2015 = false;
minifyAll();
}
else {
done(isSuccessful);
}
});

options.verbose && testProcess.stdout.pipe(process.stdout);
}
};
81 changes: 81 additions & 0 deletions scripts/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const smoke = require("./smoke-test.js");

const tests = [
// {
// dir: "babel",
// files: "packages/babel-core/src/helpers/resolve.js",
// build: "make bootstrap",
// test: "make test-only",
// babelOptions: {
// plugins: ["syntax-flow"]
// }
// },
// {
// dir: "jquery",
// files: "dist/jquery.js",
// build: "npm run build",
// test: "grunt test",
// success: "872 passing",
// },

// {
// dir: "stylelint",
// files: "lib/**/*.js",
// ignore: [
// "**/__tests__/**",
// "**/lib/rules/declaration-block-properties-order/index.js",
// "**/lib/rules/declaration-block-no-redundant-longhand-properties/index.js",
// "**/lib/rules/at-rule-empty-line-before/index.js",
// "**/lib/rules/max-empty-lines/index.js",
// "**/lib/rules/block-closing-brace-newline-before/index.js",
// "**/lib/rules/function-calc-no-unspaced-operator/index.js",
// "**/lib/rules/font-weight-notation/index.js",
// "**/lib/rules/max-line-length/index.js",
// "**/lib/rules/selector-class-pattern/index.js",
// "**/lib/rules/declaration-colon-newline-after/index.js",
// ],
// build: "npm install",
// test: "npm run jest",
// success: "Test Suites: 264 passed, 264 total",
// },
// {
// dir: "react",
// files: "build/react.js",
// build: "npm install && npm run build",
// test: "npm test",
// },

// PASS
// {
// dir: "draft-js",
// files: "dist/Draft.js",
// build: "npm cache clean && npm install",
// test: "npm test",
// verbose: false
// },
// {
// dir: "immutable-js",
// files: "dist/immutable.js",
// build: "npm install && npm run build",
// test: "npm run testonly",
// babiliOptions: {
// "unsafe": {
// typeConstructors: false,
// },
// },
// },
// {
// dir: "html-minifier",
// files: "src/htmlminifier.js",
// build: "npm install && grunt dist",
// test: "grunt qunit",
// success: "0 failed",
// },
];

(function tick(test) {
smoke(test, () => {
const test = tests.pop();
test && tick(test);
});
})(tests.pop());
1 change: 1 addition & 0 deletions scripts/stylelint
Submodule stylelint added at a4c32c