Skip to content

Commit

Permalink
Fix test configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
obuchtala committed Oct 14, 2019
1 parent 8165898 commit fc21065
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 178 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module.exports = function (config) {
basePath: '.',
frameworks: ['tap'],
files: [
'tmp/substance.cov.js',
'node_modules/substance-test/dist/test.browser.js',
'tmp/substance.istanbul.js',
'tmp/tests.js'
],
browsers: ['Firefox', 'Chrome'],
Expand Down
58 changes: 9 additions & 49 deletions make.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,36 @@
const b = require('substance-bundler')
const rollup = require('substance-bundler/extensions/rollup')
const postcss = require('substance-bundler/extensions/postcss')
const fork = require('substance-bundler/extensions/fork')
const karma = require('substance-bundler/extensions/karma')

const libConfig = require('./rollup.config.substance')
const libraryConfig = require('./rollup.config.library')
const vendorConfig = require('./rollup.config.vendor')
const testConfig = require('./rollup.config.test')

const DIST = 'dist/'

b.task('clean', () => {
b.rm('./dist')
b.rm('./tmp')
b.rm('./coverage')
})

b.task('default', ['clean', 'css', 'lib'])
b.task('default', ['clean'])

// Default dev mode, only browser bundles are made and no ES5 transpilation happens
b.task('dev', ['clean', 'css', 'lib:browser', 'test:browser'])
b.task('dev', ['clean', 'test:browser'])

b.task('build', ['clean', 'css', 'lib'])
b.task('build', ['clean'])

b.task('test', ['test:node', 'cover'])
.describe('runs the test suite')

b.task('css', () => {
postcss(b, {
from: 'substance.css',
to: DIST + 'substance.css'
})
postcss(b, {
from: 'substance-pagestyle.css',
to: DIST + 'substance-pagestyle.css'
})
postcss(b, {
from: 'substance-reset.css',
to: DIST + 'substance-reset.css'
})
})

b.task('lib', () => {
rollup(b, libConfig({ target: 'all' }))
})

b.task('lib:browser', () => {
rollup(b, libConfig({ target: 'browser' }))
})

b.task('lib:node', () => {
rollup(b, libConfig({ target: 'node' }))
})

b.task('lib:es', () => {
rollup(b, libConfig({ target: 'es' }))
})

b.task('test', ['test:browser', 'test:node'])
b.task('test', ['test:browser'])

b.task('test:browser', ['lib:browser'], () => {
b.task('test:browser', () => {
rollup(b, libraryConfig())
rollup(b, testConfig({ target: 'browser' }))
}).describe('builds the test-suite for the browser (open test/index.html)')

b.task('test:node', ['lib:node'], () => {
rollup(b, testConfig({ target: 'node' }))
fork(b, require.resolve('substance-test/bin/test'), ['./tmp/tests.cjs.js'], { verbose: true })
}).describe('runs the test suite in nodejs')

b.task('cover', () => {
rollup(b, libConfig({ target: 'coverage' }))
rollup(b, testConfig({ target: 'browser' }))
rollup(b, libraryConfig({ coverage: true }))
rollup(b, testConfig())
karma(b, {
browsers: process.env.TRAVIS ? ['ChromeTravis', 'Firefox'] : ['Chrome']
})
Expand Down
41 changes: 41 additions & 0 deletions rollup.config.library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const nodeResolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const istanbul = require('substance-bundler/extensions/rollup/rollup-plugin-istanbul')

// This is now used for browser tests and coverage
module.exports = function (options = {}) {
const config = {
input: 'index.es.js',
output: {
file: 'tmp/substance.js',
format: 'umd',
name: 'substance',
sourcemap: true,
sourcemapRoot: __dirname,
sourcemapPrefix: 'substance'
},
plugins: [
nodeResolve(),
commonjs({
include: [
'node_modules/boolbase/**/*',
'node_modules/css-what/**/*',
'node_modules/domelementtype/**/*',
'node_modules/nth-check/**/*'
]
})
]
}
if (options.coverage) {
config.output.file = 'tmp/substance.istanbul.js'
config.plugins.push(istanbul({
include: [
'dom/*.js',
'model/*.js',
'editor/*.js',
'util/*.js'
]
}))
}
return config
}
76 changes: 0 additions & 76 deletions rollup.config.substance.js

This file was deleted.

53 changes: 12 additions & 41 deletions rollup.config.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
module.exports = function (options = {}) {
let target = options.target || 'all'
let config = []
if (target === 'browser' || target === 'all') {
config.push({
input: 'test/index.js',
output: {
file: 'tmp/tests.js',
format: 'umd',
name: 'tests',
globals: {
'substance': 'window.substance',
'substance-test': 'window.substanceTest'
},
sourcemap: true
},
external: [ 'substance', 'substance-test' ]
})
}
if (target === 'node' || target === 'all') {
config.push({
input: 'test/index.js',
output: {
file: 'tmp/tests.cjs.js',
format: 'cjs',
sourcemap: true
},
external: ['substance', 'substance-test'],
plugins: [
_patchNodeTest()
]
})
}
return config
}

function _patchNodeTest () {
return {
name: 'patch-node-test',
generateBundle (options, bundle, isWrite) {
let output = bundle['tests.cjs.js']
output.code = output.code.replace("'substance'", "'../dist/substance.cjs.js'")
}
input: 'test/index.js',
output: {
file: 'tmp/tests.js',
format: 'umd',
name: 'tests',
globals: {
'substance': 'window.substance',
'substance-test': 'window.substanceTest'
},
sourcemap: true
},
external: [ 'substance', 'substance-test' ]
}
}
12 changes: 12 additions & 0 deletions test/_initLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function (_module) {
const path = require('path')
// create the ESM loader first
let _require = require('esm')(_module)
// and let 'module-alias' register on top of the ESM loaded
const moduleAlias = _require('module-alias')
const substanceEntryPoint = path.join(__dirname, '..', 'index.es.js')
moduleAlias.addAlias('substance', substanceEntryPoint)
// register the alias module loaded
moduleAlias()
return _require
}
2 changes: 2 additions & 0 deletions test/_runTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const _require = require('./_initLoader')(module)
_require('./index.js')
3 changes: 1 addition & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<head>
<title>Substance Testsuite</title>
<link href='../node_modules/substance-test/dist/test.css' rel='stylesheet' type='text/css'/>
<script type="text/javascript" src="../node_modules/substance/dist/substance.js"></script>
<script type="text/javascript" src="../node_modules/substance-test/dist/testsuite.js"></script>
<script type="text/javascript" src="../dist/substance.js"></script>
<script type="text/javascript" src="../tmp/substance.js"></script>
<script type="text/javascript" src="../tmp/tests.js"></script>
</head>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion test/karma.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<head>
<title>Substance Testsuite (for Karma)</title>
<script type="text/javascript" src="../tmp/substance.cov.js"></script>
<script type="text/javascript" src="../node_modules/substance-test/dist/test.browser.js"></script>
<script type="text/javascript" src="../tmp/substance.cov.js"></script>
<script type="text/javascript" src="../tmp/tests.js"></script>
</head>
<script type="text/javascript">
Expand Down
13 changes: 5 additions & 8 deletions test/shared/testHelpers.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { platform, DefaultDOMElement as DOM, DefaultDOMElement } from 'substance'

// ATTENTION: have to use a custom getMountPoint because
// during the tests we change the behavior of platform and DefaultDOMElement
export function getMountPoint (t) {
if (platform.inBrowser) {
if (t.sandbox) {
// let el = t.sandbox.createElement('div')
// HACK: struggling to avoid that the wron substance API is used
// i.e. substance-test is using its own version. When using the sandbox element
// generated by the test-suite, we will not 'see' elements and components
// created with the substance API used here
// ATTENTION: we can not use substanceTest.getMountPount()
// because we have use a different DOMElement implementation here.
// thus we take the native element of t.sandbox (which is created using substanceTest's internal substance impl)
// and wrap it using the correct DOM implementation
let el = DefaultDOMElement.wrap(window.document).createElement('div')
t.sandbox.append(el)
DefaultDOMElement.wrap(t.sandbox.getNativeElement()).append(el)
return el
} else {
let bodyEl = DOM.wrap(window.document.body)
Expand Down

0 comments on commit fc21065

Please sign in to comment.