Skip to content

Commit

Permalink
start to get test system running again
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed May 14, 2020
1 parent 207972f commit c4500e6
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/packages/*/locales/*
/packages/*/locales-all.js

/tests-*.*

# continued in packages-premium/.gitignore

node_modules
Expand Down
102 changes: 88 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const path = require('path')
const globby = require('globby')
const handlebars = require('handlebars')
const { src, dest, watch, parallel } = require('gulp')
const { src, dest, watch, parallel, series } = require('gulp')
const { readFile, writeFile } = require('./scripts/lib/util')
const fs = require('fs')
const exec = require('./scripts/lib/shell').sync.withOptions({ // always SYNC!
live: true,
exitOnError: true
// TODO: flag for echoing command?
})

const SRC_LOCALE_DIR = 'packages/core/src/locales'
const SRC_LOCALE_EXT = '.ts'
Expand Down Expand Up @@ -61,13 +66,6 @@ const PKG_DIRS = [
'!packages?(-premium)/{core-vdom,bundle,__tests__}'
]

const exec = require('./scripts/lib/shell').sync.withOptions({
live: true,
exitOnError: true
// TODO: flag for echoing command?
})


async function distDirs() {
let pkgDirs = await globby(PKG_DIRS, { onlyDirectories: true })

Expand Down Expand Up @@ -117,13 +115,11 @@ async function distLinks() {
async function vdomLink() {
let pkgRoot = 'packages/core-vdom'
let outPath = path.join(pkgRoot, 'src/vdom.ts')
let newTarget = // relative to outPath
process.env.FULLCALENDAR_FORCE_REACT
? '../../../packages-contrib/react/src/vdom.ts'
: 'vdom-preact.ts'
let newTarget = process.env.FULLCALENDAR_FORCE_REACT
? '../../../packages-contrib/react/src/vdom.ts' // relative to outPath
: 'vdom-preact.ts'

let currentTarget

try {
currentTarget = fs.readlinkSync(outPath)
} catch(ex) {} // if doesn't exist
Expand All @@ -132,7 +128,7 @@ async function vdomLink() {
exec([ 'rm', '-rf', outPath ])
currentTarget = null

console.log('Clearing tsbuildinfo because vdom symlink changed') // TODO: use gulp util?
console.log('Clearing tsbuildinfo because vdom symlink changed') // TODO: use gulp warn util?
exec([ 'rm', '-rf', path.join(pkgRoot, 'tsconfig.tsbuildinfo') ])
}

Expand All @@ -143,6 +139,12 @@ async function vdomLink() {



/*
copy over the vdom files that were externalized by rollup.
we externalize these for two reasons:
- when a consumer build system sees `import './vdom'` it's more likely to treat it with side effects.
- rollup-plugin-dts was choking on the namespace declarations in the tsc-generated vdom.d.ts files.
*/
const VDOM_FILE_MAP = {
'packages/core-vdom/tsc/vdom.{js,d.ts}': 'packages/core/dist',
'packages/common/tsc/vdom.{js,d.ts}': 'packages/common/dist'
Expand All @@ -161,3 +163,75 @@ function parallelMap(map, execute) {
return task
}))
}





const exec2 = require('./scripts/lib/shell').sync

exports.testsIndex = testsIndex
exports.testsIndexWatch = series(testsIndex, testsIndexWatch)

async function testsIndex() {
let res = exec2(
'find packages*/__tests__/tsc -mindepth 2 -name \'*.js\' -print0 | ' +
'xargs -0 grep -E "(fdescribe|fit)\\("'
)

if (!res.success && res.stderr) { // means there was a real error
throw new Error(res.stderr)
}

let files

if (!res.success) { // means there were no files that matched
let { stdout } = exec2('find packages*/__tests__/tsc -mindepth 2 -name \'*.js\'')
files = stdout.trim()
files = !files ? [] : files.split('\n')
files = uniqStrs(files)
files.sort() // work around OS-dependent sorting ... TODO: better sorting that knows about filename slashes
console.log(`[test-index] All ${files.length} test files.`) // TODO: use gulp log util?

} else {
files = res.stdout.trim()
files = !files ? [] : files.split('\n')
files = files.map((line) => line.trim().split(':')[0]) // TODO: do a max split of 1
files = uniqStrs(files)
files.sort() // work around OS-dependent sorting
console.log(
'[test-index] Only test files that have fdescribe/fit:\n' + // TODO: use gulp log util?
files.map((file) => ` - ${file}`).join('\n')
)
}

let mainFiles = globby.sync('packages*/__tests__/tsc/main.js')
files = mainFiles.concat(files)

let code =
files.map(
(file) => `import ${JSON.stringify('./' + file)}`
).join('\n') +
'\n'

await writeFile('tests-index.js', code)
}

function testsIndexWatch() {
return watch(
[ 'packages/__tests__/tsc', 'packages-premium/__tests__/tsc' ], // wtf won't globs work for this?
exports.testsIndex
)
}

/*
TODO: make unnecessary. have grep do this instead with the -l option:
https://stackoverflow.com/questions/6637882/how-can-i-use-grep-to-show-just-filenames-on-linux
*/
function uniqStrs(a) {
let hash = {}
for (let item of a) {
hash[item] = true
}
return Object.keys(hash)
}
20 changes: 6 additions & 14 deletions karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [

// jquery-related deps should attach globally first
'node_modules/jquery/dist/jquery.js', // because of jquery-simulate and needing-to-be-first
'node_modules/jquery-simulate/jquery.simulate.js', // operates on global jQuery
'node_modules/jasmine-jquery/lib/jasmine-jquery.js', // weird this/root reference confuses rollup

'tmp/tests-compiled/config.js', // a way to dump variables into the test environment
{ pattern: 'tmp/tests-compiled/main.js', nocache: true },
{ pattern: 'tmp/tests-compiled/main.css', watched: false }, // let the JS cause the refresh
{ pattern: 'tmp/tests-compiled/*.map', included: false, nocache: true, watched: false }
'tmp/tests-compiled/config.js', // a way to dump variables into the test environment ... TODO: move location!!!
'tests-all.js'
],

// make console errors aware of source files
preprocessors: {
'tmp/tests-compiled/*.+(js|css)': [ 'sourcemap' ]
},
// // make console errors aware of source files
// preprocessors: {
// 'tmp/tests-compiled/*.+(js|css)': [ 'sourcemap' ]
// },

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage', 'verbose'
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"rollup:packages": "gulp distDirs && rollup -c rollup.packages.js && gulp copyVDom",
"rollup:bundles": "rollup -c rollup.bundles.js",
"rollup:bundles:watch": "rollup -c rollup.bundles.js --watch",
"test": "concurrently --restart-tries 999 --prefix none 'karma start karma.config.js'",
"test:ci": "karma start karma.config.js ci",
"test": "gulp testsIndex && webpack --config webpack.tests.js && karma start karma.config.js",
"test:old": "concurrently --restart-tries 999 --prefix none 'karma start karma.config.js'",
"ci": "./scripts/ci.sh",
"archive": "gulp archive",
"preversion": "./scripts/update-example-dates.sh && npm run clean",
Expand All @@ -72,6 +72,7 @@
"chokidar": "^2.1.5",
"components-jqueryui": "github:components/jqueryui",
"concurrently": "^4.1.1",
"css-loader": "^3.5.3",
"dragula": "^3.7.2",
"eslint": "^5.16.0",
"eslint-config-standard": "^12.0.0",
Expand Down Expand Up @@ -111,9 +112,12 @@
"rrule": "^2.6.2",
"sass": "^1.26.3",
"shelljs": "^0.8.3",
"style-loader": "^1.2.1",
"tslint": "^5.16.0",
"tslint-config-standard": "^8.0.1",
"typescript": "~3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"xhr-mock": "^2.5.1",
"yarn": "1.18.0"
}
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion packages/__tests__/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

import 'jquery-simulate/jquery.simulate.js'
import 'jasmine-jquery'

import './lib/globals'
import './lib/install-plugins'
import './main.css'
import '../main.css'

// all of the non-lib .js files within subdirectories will be automatically included...
2 changes: 2 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ rm -rf packages/*/dist
rm -rf packages/*/locales
rm -rf packages/*/locales-all.js

rm -rf tests-*.*

rm -rf packages-premium/*/tsconfig.tsbuildinfo
rm -rf packages-premium/*/tsc
rm -rf packages-premium/*/dist
Expand Down
10 changes: 7 additions & 3 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ cd "`dirname $0`/.." # always start in project root
# rewire the @fullcalendar/angular package.
# we still want yarn to install its dependencies,
# but we want other packages to reference it by its dist/fullcalendar folder
cd node_modules/@fullcalendar
rm -f angular
ln -s ../../packages-contrib/angular/dist/fullcalendar angular
rm -f node_modules/@fullcalendar/angular
ln -s ../../packages-contrib/angular/dist/fullcalendar node_modules/@fullcalendar/angular


# same concept for fullcalendar-tests
rm -f node_modules/fullcalendar-tests
ln -s ../packages/__tests__/tsc node_modules/fullcalendar-tests
2 changes: 1 addition & 1 deletion tsconfig.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"noImplicitUseStrict": true,
"importHelpers": true,
"resolveJsonModule": true,
"allowJs": false,
"allowJs": true,
"checkJs": false,
"jsx": "react",
"jsxFactory": "h",
Expand Down
26 changes: 26 additions & 0 deletions webpack.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require('path')
const webpack = require('webpack')

module.exports = {
mode: 'development',
devtool: 'sourcemap',
entry: './tests-index.js',
module: {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
}
]
},
output: {
filename: 'tests-all.js',
path: __dirname
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
}
23 changes: 20 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4022,7 +4022,7 @@ css-declaration-sorter@^4.0.1:
postcss "^7.0.1"
timsort "^0.3.0"

css-loader@^3.0.0, css-loader@^3.4.2:
css-loader@^3.0.0, css-loader@^3.4.2, css-loader@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-3.5.3.tgz#95ac16468e1adcd95c844729e0bb167639eb0bcf"
integrity sha512-UEr9NH5Lmi7+dguAm+/JSPovNjYbm2k3TK58EiwQHzOHH5Jfq1Y+XoP2bQO6TMn7PptMd0opxxedAWcaSTRKHw==
Expand Down Expand Up @@ -8452,6 +8452,15 @@ loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3, loader-utils@^1.4
emojis-list "^3.0.0"
json5 "^1.0.1"

loader-utils@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.0.tgz#e4cace5b816d425a166b5f097e10cd12b36064b0"
integrity sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==
dependencies:
big.js "^5.2.2"
emojis-list "^3.0.0"
json5 "^2.1.2"

locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
Expand Down Expand Up @@ -13103,6 +13112,14 @@ style-loader@1.0.0:
loader-utils "^1.2.3"
schema-utils "^2.0.1"

style-loader@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/style-loader/-/style-loader-1.2.1.tgz#c5cbbfbf1170d076cfdd86e0109c5bba114baa1a"
integrity sha512-ByHSTQvHLkWE9Ir5+lGbVOXhxX10fbprhLvdg96wedFZb4NDekDPxVKv5Fwmio+QcMlkkNfuK+5W1peQ5CUhZg==
dependencies:
loader-utils "^2.0.0"
schema-utils "^2.6.6"

stylehacks@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/stylehacks/-/stylehacks-4.0.3.tgz#6718fcaf4d1e07d8a1318690881e8d96726a71d5"
Expand Down Expand Up @@ -14335,7 +14352,7 @@ webidl-conversions@^4.0.2:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==

webpack-cli@^3.2.1, webpack-cli@^3.3.0:
webpack-cli@^3.2.1, webpack-cli@^3.3.0, webpack-cli@^3.3.11:
version "3.3.11"
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-3.3.11.tgz#3bf21889bf597b5d82c38f215135a411edfdc631"
integrity sha512-dXlfuml7xvAFwYUPsrtQAA9e4DOe58gnzSxhgrO/ZM/gyXTBowrsYeubyN4mqGhYdpXMFNyQ6emjJS9M7OBd4g==
Expand Down Expand Up @@ -14461,7 +14478,7 @@ webpack@4.41.2:
watchpack "^1.6.0"
webpack-sources "^1.4.1"

webpack@^4.12.0, webpack@^4.29.0, webpack@^4.29.6:
webpack@^4.12.0, webpack@^4.29.0, webpack@^4.29.6, webpack@^4.43.0:
version "4.43.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.43.0.tgz#c48547b11d563224c561dad1172c8aa0b8a678e6"
integrity sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g==
Expand Down

0 comments on commit c4500e6

Please sign in to comment.