Skip to content

Commit 7d530f8

Browse files
committed
Add jest test harness
1 parent 831af4d commit 7d530f8

7 files changed

Lines changed: 44 additions & 67 deletions

File tree

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@ This package serves as the master build process for transpiling and bundling the
44

55
Individual library builds are run from the respective library packages. Combined builds are meant for CDN distribution and are run from the [CreateJS package](https://github.com/createjs/createjs).
66

7-
## Installation
8-
9-
From the library package, install:
10-
###### `npm install @createjs/build`
11-
127
## Usage
138

149
Tasks within this package are run via npm scripts in the library packages. Here is a summary of tasks that this package can run:
1510

16-
###### `npm run build -- [--production] [--combined] [--format=global,module,common]`
11+
###### `npm run build -- [--production] [--combined] [--format=cjs,iife]`
1712

1813
- transpile and bundle ES2015+ source to ES5 via Rollup & Babel
19-
- `--production` minified builds
14+
- `--production` iife build is minified
2015
- `--combined` from CreateJS package for combined builds
21-
- `--format` specify which bundle formats to export, defaults to all
16+
- `--format` specify which Rollup bundle formats to export, defaults to all
2217

23-
###### `npm run plugins -- [--production] [--format=global,common] [--files=FileName]`
18+
###### `npm run plugins -- [--production] [--format=cjs,iife] [--files=FileName]`
2419

2520
- transpile ES2015+ plugin source to ES5 via Rollup & Babel
26-
- `--production` minified output
21+
- `--production` iife build is minified
2722
- `--format` specify which bundle formats to export, 'module' is disabled
28-
- `--files` only transpile specific files (sans file extension)
23+
- `--files` only transpile specific files (no file extension)
2924

3025
###### `npm run dev`
3126

3227
- transpile and bundle ES2015+ source to ES5 via Rollup & Babel
3328
- non-minified, includes sourcemaps
34-
- only bundles 'global' module as that is what is imported by examples
29+
- only bundles iife module as that is what is imported by examples
3530
- starts a browser-sync instance for testing examples and tutorials
3631
- watches source files for changes, re-compiling and reloading browser
3732

babel.config.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
const browsers = ["IE 9"];
2+
const loose = true;
13
module.exports = {
4+
// default preset for prod+dev
5+
presets: [
6+
[
7+
"@babel/env", {
8+
targets: {
9+
browsers: browsers
10+
},
11+
modules: false,
12+
loose: loose
13+
}
14+
]
15+
],
216
env: {
3-
development: {
4-
presets: [
5-
[
6-
"@babel/env", {
7-
targets: {
8-
browsers: ["IE 9"]
9-
},
10-
modules: false,
11-
loose: true
12-
}
13-
]
14-
]
15-
},
17+
// unit testing preset
1618
test: {
1719
presets: [
1820
[
1921
"@babel/env", {
2022
targets: {
21-
browsers: ["IE 9"]
23+
browsers: browsers
2224
},
23-
loose: true
25+
loose: loose
2426
}
2527
]
2628
]

gulpfile.babel.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
// gulp
21
const gulp = require("gulp");
3-
// rollup
42
const rollup = require("rollup");
53
const babel = require("rollup-plugin-babel");
64
const multiEntry = require("rollup-plugin-multi-entry");
75
const nodeResolve = require("rollup-plugin-node-resolve");
86
const commonjs = require("rollup-plugin-commonjs");
97
const cleanup = require("rollup-plugin-cleanup");
108
const uglify = require("rollup-plugin-uglify").uglify;
11-
// utils
129
const utils = require("./tasks/utils");
1310
const template = require("lodash.template");
1411
const path = require("path");
15-
// other
1612
const del = require("del");
1713
const browserSync = require("browser-sync");
1814

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@
2121
"type": "git",
2222
"url": "https://github.com/createjs/build.git"
2323
},
24-
"devDependencies": {
24+
"scripts": {
25+
"test": "jest -c ./tests/jest.config.js"
26+
},
27+
"dependencies": {
2528
"@babel/core": "^7.1.2",
2629
"@babel/preset-env": "^7.1.0",
2730
"@babel/register": "^7.0.0",
2831
"ansi-colors": "^3.2.1",
32+
"babel-core": "7.0.0-bridge.0",
33+
"babel-jest": "^23.6.0",
2934
"browser-sync": "^2.26.3",
35+
"canvas": "^2.1.0",
3036
"del": "^3.0.0",
3137
"fancy-log": "^1.3.2",
3238
"gulp": "^4.0.0",
39+
"jest": "^23.6.0",
3340
"lodash.template": "^4.4.0",
3441
"minimist": "^1.2.0",
3542
"rollup": "^0.66.6",

tests/jest.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1+
const utils = require("../tasks/utils");
12
module.exports = {
2-
rootDir: "../",
3+
rootDir: utils.base,
34
testMatch: [
45
"<rootDir>/tests/spec/**/*.js"
56
],
67
setupTestFrameworkScriptFile: "@createjs/build/tests/setup",
78
collectCoverage: true,
89
collectCoverageFrom: [
9-
"src/**/!(main).js"
10+
"<rootDir>/src/**/!(main).js"
1011
],
1112
coveragePathIgnorePatterns: [
1213
"/node_modules/",
1314
"/tests/"
1415
],
15-
coverageDirectory: "./tests/coverage/",
16+
coverageDirectory: "<rootDir>/tests/coverage/",
1617
coverageReporters: [
1718
"html",
1819
"text"
1920
],
2021
notify: true,
21-
verbose: true,
22-
testEnvironmentOptions: {
23-
resources: "usable"
24-
}
22+
verbose: true
2523
};

tests/karma.config.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
var path = require("path");
2-
3-
// get base and pkg
4-
var base, pkg;
5-
try {
6-
base = path.resolve(process.cwd(), "../../../");
7-
pkg = require(`${base}/package.json`);
8-
} catch (e) {
9-
base = process.platform === "win32" ? process.env.PWD : path.resolve(process.env.PWD, "../../../");
10-
pkg = require(`${base}/package.json`);
11-
}
1+
const path = require("path");
2+
const utils = require("../tasks/utils");
123

134
// create expect adapter
14-
var expectPlugin = {
15-
"framework:expect": ["factory", function (files) {
5+
const expectPlugin = {
6+
"framework:expect": ["factory", files => {
167
files.unshift({
178
included: true, served: true, watched: false,
189
pattern: path.join(path.dirname(require.resolve("expect")), "build-es5", "index.js")
@@ -21,11 +12,11 @@ var expectPlugin = {
2112
}
2213
expectPlugin["framework:expect"][1].$inject = ["config.files"];
2314

24-
module.exports = function (config) {
15+
module.exports = config => {
2516
config.set({
26-
basePath: base,
17+
basePath: utils.base,
2718
frameworks: ["expect"],
2819
plugins: [expectPlugin],
29-
files: [pkg.browser]
20+
files: [utils.pkg.browser]
3021
});
3122
};

0 commit comments

Comments
 (0)