Skip to content

Commit

Permalink
Include all sources into coverage statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
obuchtala committed Mar 13, 2017
1 parent 5b98b60 commit b7ee19f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
71 changes: 34 additions & 37 deletions make.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const install = require('substance-bundler/extensions/install')
const isInstalled = require('substance-bundler/util/isInstalled')
const path = require('path')
const fs = require('fs')
const merge = require('lodash.merge')

// Helpers
// -------
Expand All @@ -23,6 +24,19 @@ function buildCss() {
})
}

const COMMON_SETTINGS = (custom) => { return merge({
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
},
// for libraries that we want to include into the browser bundle
// but need to be pre-bundled (see buildVendor())
// we register a redirect to the the pre-bundled file
alias: {
'sanitize-html': path.join(__dirname, 'vendor/sanitize-html.min.js'),
}
}, custom)}

/*
Building a single Stencila lib bundle
*/
Expand All @@ -42,21 +56,11 @@ function buildStencila() {
dest : 'build/stencila.cjs.js',
format: 'cjs',
}
b.js('index.es.js', {
b.js('index.es.js', COMMON_SETTINGS({
targets: [browserTarget, nodejsTarget],
// Externals are not include into the bundle
external: ['substance', 'substance-mini', 'brace', 'katex'],
// for libraries that we want to include into the browser bundle
// but need to be pre-bundled (see buildVendor())
// we register a redirect to the the pre-bundled file
alias: {
'sanitize-html': path.join(__dirname, 'vendor/sanitize-html.min.js'),
},
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
}
})
}))
}

function buildExamples() {
Expand All @@ -77,59 +81,52 @@ function buildExamples() {

function buildTests(target) {
if (target === 'browser') {
b.js('tests/**/*.test.js', {
b.js('tests/**/*.test.js', COMMON_SETTINGS({
dest: 'tmp/tests.js',
format: 'umd',
moduleName: 'tests',
external: {
'substance': 'window.substance',
'tape': 'substanceTest.test'
},
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
}
})
}))
} else if (target === 'nodejs') {
b.js('tests/**/*.test.js', {
b.js('tests/**/*.test.js', COMMON_SETTINGS({
dest: 'tmp/tests.cjs.js',
format: 'cjs',
external: ['substance', 'tape'],
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
}
})
external: ['substance', 'tape']
}))
} else if (target === 'cover') {
// TODO: we must include the whole source code to see the real coverage
// right now we only see the coverage on the files which
// are actually imported by tests.
b.js('tests/**/*.test.js', {
b.js(['index.es.js', 'tests/**/*.test.js'], COMMON_SETTINGS({
dest: 'tmp/tests.cov.js',
format: 'cjs',
istanbul: {
include: ['src/**/*.js']
},
external: ['substance', 'tape'],
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
}
})
// add all modules which can be stubbed out by an empty object
ignore: [ 'brace', 'katex' ],
// these should be used directly from nodejs, not bundled
external: [
'substance', 'substance-mini', 'tape', 'stream',
]
}))
}
}

function buildSingleTest(testFile) {
const dest = path.join(__dirname, 'tmp', testFile)
b.js(testFile, {
b.js(testFile, COMMON_SETTINGS({
dest: dest,
format: 'cjs',
external: ['substance', 'tape'],
// paramaters that are passed to the rollup-commonjs-plugin
commonjs: {
namedExports: { 'acorn/dist/walk.js': [ 'simple', 'base' ] }
}
})
}))
return dest
}

Expand Down Expand Up @@ -171,7 +168,7 @@ function minifiedVendor(src, name, opts = {}) {
// unpublished version of substance
function buildDeps() {
if (!fs.existsSync(path.join(__dirname, 'node_modules/substance/dist/substance.js'))){
b.make('substance', 'browser:pure')
b.make('substance')
}
}

Expand Down Expand Up @@ -226,13 +223,13 @@ b.task('examples', ['stencila'], () => {
})
.describe('Build the examples.')

b.task('test', ['clean'], () => {
b.task('test', ['clean', 'deps'], () => {
buildTests('nodejs')
fork(b, 'node_modules/substance-test/bin/test', 'tmp/tests.cjs.js')
})
.describe('Runs the tests and generates a coverage report.')

b.task('cover', ['clean'], () => {
b.task('cover', ['clean', 'deps'], () => {
buildTests('cover')
fork(b, 'node_modules/substance-test/bin/coverage', 'tmp/tests.cov.js')
})
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
"brace": "^0.9.1",
"eslint": "^3.12.2",
"istanbul": "^0.4.5",
"lodash.merge": "^4.6.0",
"sanitize-html": "^1.13.0",
"sprintf-js": "^1.0.3",
"substance-bundler": "^0.13.4",
"substance-bundler": "^0.13.5",
"substance-test": "^0.8.3",
"tape": "^4.6.3"
}
Expand Down

0 comments on commit b7ee19f

Please sign in to comment.