Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Add simple smoke-test #240

Merged
merged 1 commit into from
Mar 31, 2017
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ test/tmp
*.log
.vscode
.nyc_output
tmp
babel-preset-env-*.tgz
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ scripts
.travis.yml
codecov.yml
yarn.lock
.nyc_output
.vscode
babel-preset-env-*.tgz
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ install:
- $PKG_CMD install
script:
- 'if [ -n "${LINT-}" ]; then $PKG_CMD run lint ; fi'
- 'if [ -z "${LINT-}" ]; then $PKG_CMD run test-ci ; fi'
- 'if [ -n "${SMOKE_TEST-}" ]; then node scripts/smoke-test.js ; fi'
- 'if [ -z "${LINT-}" ] && [ -z "${SMOKE_TEST-}" ]; then $PKG_CMD run test-ci ; fi'
matrix:
fast_finish: true
exclude:
Expand All @@ -38,5 +39,7 @@ matrix:
include:
- node_js: "node"
env: LINT=true PKG_CMD="npm"
- node_js: "node"
env: SMOKE_TEST=true PKG_CMD="npm"

after_success: 'if [ -z "${LINT-}" ]; then npm run coverage-ci ; fi'
after_success: 'if [ -z "${LINT-}" ] && [ -z "${SMOKE_TEST-}" ]; then npm run coverage-ci ; fi'
69 changes: 69 additions & 0 deletions scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require("fs-extra");
const execSync = require("child_process").execSync;
const path = require("path");
const pkg = require("../package.json");

let errorOccurred = false;

const tempFolderPath = path.join(__dirname, "../tmp");
const packPath = path.join(__dirname, `../babel-preset-env-${pkg.version}.tgz`);

try {
console.log("Creating package");
execSync("npm pack");

console.log("Setting up smoke test");
fs.ensureDir(tempFolderPath);

fs.writeFileSync(
path.join(tempFolderPath, "package.json"),
`
{
"name": "babel-preset-env-smoke-test",
"private": true,
"version": "1.0.0",
"scripts": {
"build": "babel index.js --out-file index.es6"
},
"dependencies": {
"babel-cli": "*",
"babel-preset-env": "${packPath}"
}
}
`);

fs.writeFileSync(
path.join(tempFolderPath, ".babelrc"),
`
{
"presets": [
["env", {
modules: false,
useBuiltIns: true
}]
]
}
`
);

fs.writeFileSync(
path.join(tempFolderPath, "index.js"),
`
import "babel-polyfill";
1 ** 2;
`
);

process.chdir(tempFolderPath);

console.log("Running smoke test");
execSync("npm install && npm run build");
} catch (e) {
errorOccurred = true;
}

console.log("Cleaning up");
fs.removeSync(tempFolderPath);
fs.removeSync(packPath);

process.exit(errorOccurred ? 1 : 0);