Skip to content

Commit

Permalink
done migrate tests to lerna & remove rollup-plugin-typescript2 devDep…
Browse files Browse the repository at this point in the history
…endency
  • Loading branch information
giabao committed Apr 22, 2019
1 parent 1839834 commit b299474
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 98 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ node_modules
*.tsbuildinfo
*.test.js
*.test.amd.js
*.test.iife.js
*.test.d.ts
/test/*.d.ts
!/test/typings.d.ts
/packages/core/test/qunit-ex.js*
/packages/core/test/qunit-ex.d.ts
/packages/test-util/*.js*
/packages/test-util/*.d.ts
!/packages/test-util/typings.d.ts
/packages/*/lib/
!/packages/*/lib/types/types.d.ts
yarn-error.log
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
"clean": "node scripts/clean.js && rimraf .rpt2_cache",
"tsc:es2018": "tsc -b",
"watch:tsc_es2018": "tsc -b --watch --pretty",
"tsc:es5": "lerna exec --stream --parallel -- ../../node_modules/.bin/tsc --outDir lib/esm5 --target es5",
"watch:tsc_es5": "lerna exec --stream --parallel -- ../../node_modules/.bin/tsc --outDir lib/esm5 --target es5 --watch --pretty",
"tsc:es5": "lerna exec --no-private --stream --parallel -- ../../node_modules/.bin/tsc -p src/ --outDir lib/esm5 --target es5",
"watch:tsc_es5": "lerna exec --no-private --stream --parallel -- ../../node_modules/.bin/tsc -p src/ --outDir lib/esm5 --target es5 --watch --pretty",
"rollup:src": "rollup -c scripts/rollup.config.js",
"watch:rollup_src": "FORCE_COLOR=1 rollup -c scripts/rollup.config.js --watch",
"build:src": "npm-run-all tsc:es2018 tsc:es5 rollup:src",
"build:test": "rollup -c scripts/rollup.config.test.js",
"watch:test": "FORCE_COLOR=1 rollup -c scripts/rollup.config.test.js --watch",
"build": "run-s tsc:scripts build:src build:test",
"prerelease": "TODO run-s clean build dist-prepare",
"prerelease": "run-s clean build",
"release": "TODO node scripts/publish.js",
"watch": "run-p -l watch:*",
"test": "echo 'pls browse test/*.html for testing'"
Expand Down Expand Up @@ -85,7 +85,6 @@
"rollup-plugin-re": "^1.0.7",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.20.1",
"rollup-plugin-uglify": "^6.0.2",
"typescript": "^3.4.1"
}
Expand Down
14 changes: 6 additions & 8 deletions packages/classapplier/test/index.amd.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<script src="../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css">
<script src="../../node_modules/requirejs/require.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
<script src="../../../node_modules/requirejs/require.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script>
QUnit.config.autostart = false;
var paths = {};
var dist = "../../dist/";
requirejs.config({
baseUrl: '../../dist/',
baseUrl: '../../',
paths: {
"rangy2": "core/bundles/index.umd",
"rangy-classapplier": "classapplier/bundles/index.umd"
"@rangy/core": "core/lib/bundles/index.umd",
"@rangy/classapplier": "classapplier/lib/bundles/index.umd"
}
});
requirejs(['./index.test.amd.js'], function () {
Expand Down
11 changes: 5 additions & 6 deletions packages/classapplier/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<!-- load rangy2 here in `head` to verify that rangy2 can init without need dom ready -->
<script src="../../dist/core/bundles/index.umd.min.js"></script>
<script src="../../dist/classapplier/bundles/index.umd.min.js"></script>
<script src="../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css">
<script src="../qunit-ex.js"></script>
<script src="../../core/lib/bundles/index.umd.min.js"></script>
<script src="../lib/bundles/index.umd.min.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="index.test.js"></script>
<script src="index.test.iife.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions packages/classapplier/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ClassApplier, createClassApplier} from 'rangy-classapplier';
import * as rangy from 'rangy2';
import "@rangy/test-util";

import "../qunit-ex";
import {ClassApplier, createClassApplier} from '@rangy/classapplier';
import * as rangy from '@rangy/core';

QUnit.module("Class Applier module tests");

Expand Down
8 changes: 8 additions & 0 deletions packages/classapplier/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{"path": "../src"},
{"path": "../../core/src"},
{ "path": "../../test-util"}
]
}
1 change: 1 addition & 0 deletions packages/core/test/dom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as rangy from "@rangy/core";
import "@rangy/test-util/qunit-ex";

QUnit.module("Range");

Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/feature.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
<script src="../lib/bundles/index.umd.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
<script src="qunit-ex.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="feature.test.js"></script>
<script src="feature.test.iife.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions packages/core/test/feature.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as rangy from "@rangy/core";
import Bowser from "bowser";
import "@rangy/test-util/qunit-ex";

const browser = Bowser.getParser(window.navigator.userAgent);
QUnit.module("Browser feature tests");
Expand Down
7 changes: 3 additions & 4 deletions packages/core/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
<script src="../lib/bundles/index.umd.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
<script src="qunit-ex.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<!--<script src="dom.test.js"></script>-->
<!--<script src="range.test.js"></script>-->
<script src="selection.test.js"></script>
<!--<script src="dom.test.iife.js"></script>-->
<script src="range.test.iife.js"></script>
<!--<script src="selection.test.iife.js"></script>-->
<!-- Next line for Acid3 tests -->
<script type="text/javascript">document.write('<iframe src="empty.html" id="selectors"><\/iframe>');</script>
</body>
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/range.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as rangy from "@rangy/core";
import {DomRange, RangyRange, DOMException, WrappedRange} from "@rangy/core";

import "./qunit-ex";
import "@rangy/test-util/qunit-ex";

var hasNativeDomRange = "createRange" in document;

Expand Down
1 change: 1 addition & 0 deletions packages/core/test/selection.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as rangy from "@rangy/core";
import {RangyRangeEx, WrappedSelection} from "@rangy/core";
import "@rangy/test-util";

var hasNativeGetSelection = "getSelection" in window;
var hasNativeDomRange = "createRange" in document;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{ "path": "../src"}
{ "path": "../src"},
{ "path": "../../test-util"}
]
}
8 changes: 4 additions & 4 deletions packages/highlighter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class Highlighter {
return intersectingHighlights;
}

highlightCharacterRanges(className, charRanges, options) {
highlightCharacterRanges(className, charRanges, options?) {
var i, len, j;
var highlights = this.highlights;
var converter = this.converter;
Expand Down Expand Up @@ -395,7 +395,7 @@ export class Highlighter {
return newHighlights;
}

highlightRanges(className, ranges, options) {
highlightRanges(className, ranges, options?) {
var selCharRanges = [];
var converter = this.converter;

Expand Down Expand Up @@ -424,7 +424,7 @@ export class Highlighter {
});
}

highlightSelection(className, options) {
highlightSelection(className, options?) {
var converter = this.converter;
var classApplier = className ? this.classAppliers[className] : false;

Expand Down Expand Up @@ -481,7 +481,7 @@ export class Highlighter {
return this.getHighlightsInSelection(selection).length > 0;
}

serialize(options) {
serialize(options?) {
var highlighter = this;
var highlights = highlighter.highlights;
var serializedType, serializedHighlights, convertType, serializationConverter;
Expand Down
11 changes: 5 additions & 6 deletions packages/highlighter/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<!-- load rangy2 here in `head` to verify that rangy2 can init without need dom ready -->
<script src="../../dist/core/bundles/index.umd.min.js"></script>
<script src="../../dist/highlighter/bundles/index.umd.min.js"></script>
<script src="../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css">
<script src="../qunit-ex.js"></script>
<script src="../../core/lib/bundles/index.umd.min.js"></script>
<script src="../lib/bundles/index.umd.min.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="index.test.js"></script>
<script src="index.test.iife.js"></script>
</body>
</html>
11 changes: 6 additions & 5 deletions packages/highlighter/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as rangy from "rangy2";
import "rangy-classapplier";
import "rangy-highlighter";
import {createRangeInHtml} from "../testutils"
import * as rangy from "@rangy/core";
import "@rangy/classapplier";
import "@rangy/highlighter";
import {createRangeInHtml} from "@rangy/test-util/testutils";
import "@rangy/test-util/qunit-ex";

QUnit.module("Highlighter module tests");

Expand All @@ -16,7 +17,7 @@ QUnit.module("Highlighter module tests");

var highlights = highlighter.highlightSelection("c1");

t.assertEquals(highlights.length, 1);
t.equal(highlights.length, 1);


//t.assertEquals(highlights.length, 1);
Expand Down
9 changes: 9 additions & 0 deletions packages/highlighter/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{"path": "../src"},
{"path": "../../core/src"},
{"path": "../../classapplier/src"},
{ "path": "../../test-util"}
]
}
11 changes: 5 additions & 6 deletions packages/serializer/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<!-- load rangy2 here in `head` to verify that rangy2 can init without need dom ready -->
<script src="../../dist/core/bundles/index.umd.js"></script>
<script src="../../dist/serializer/bundles/index.umd.js"></script>
<script src="../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css">
<script src="../qunit-ex.js"></script>
<script src="../../core/lib/bundles/index.umd.min.js"></script>
<script src="../lib/bundles/index.umd.min.js"></script>
<script src="../../../node_modules/qunit/qunit/qunit.js"></script>
<link rel="stylesheet" href="../../../node_modules/qunit/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="index.test.js"></script>
<script src="index.test.iife.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion packages/serializer/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as rangy from "rangy-serializer";
import * as rangy from "@rangy/serializer";
import "@rangy/test-util/qunit-ex";

QUnit.module("Class Applier module tests");

Expand Down
8 changes: 8 additions & 0 deletions packages/serializer/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{"path": "../src"},
{"path": "../../core/src"},
{ "path": "../../test-util"}
]
}
2 changes: 2 additions & 0 deletions packages/test-util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./qunit-ex";
export * from "./testutils";
2 changes: 1 addition & 1 deletion packages/test-util/testutils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rangy from "rangy2";
import * as rangy from "@rangy/core";
import "core-js/es/map";

export function createNodeTree(levels, copiesPerLevel) {
Expand Down
2 changes: 2 additions & 0 deletions packages/test-util/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ declare module "bowser" {
}
}
}

export * from "./index";
25 changes: 13 additions & 12 deletions scripts/rollup.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import * as glob from 'glob';
import typescript from 'rollup-plugin-typescript2'
import {packages, packagesDir} from "./util";
import {resolve, join} from "path";
import {ModuleFormat, RollupOptions} from "rollup";
import fs from "fs";
import sourceMaps from 'rollup-plugin-sourcemaps'

const commonPlugins = [
const plugins = [
nodeResolve(),
commonjs()
commonjs(),
sourceMaps(),
];

//all rangy modules are external dependencies to test code
Expand All @@ -25,16 +27,17 @@ external.forEach(n => Object.assign(globals, {[n]: 'rangy'}));

function configsFor(module: string) {
const cwd = resolve(packagesDir, module, 'test');
const plugins = [...commonPlugins, typescript({
tsconfig: resolve(cwd, 'tsconfig.json')
})];
const tsconfig = resolve(cwd, 'tsconfig.json');

if (!fs.existsSync(tsconfig)) return [];

function config(f: string, format: ModuleFormat = 'iife'): RollupOptions {
f = join(cwd, f);
return {
input: [f],
output: {
format,
file: f.replace(/\.ts$/, format == 'iife'? '.js' : `.${format}.js`),
file: f.replace(/\.js$/, `.${format}.js`),
name: 'unnamed',
globals,
sourcemap: true
Expand All @@ -44,16 +47,14 @@ function configsFor(module: string) {
}
}
const configs = glob
.sync('**/*.ts', {cwd})
.filter(f => !f.endsWith('.d.ts'))
.sync('**/*.test.js', {cwd})
.map(f => config(f));

if (module == 'classapplier') {
// push amdTestExampleConfig
configs.push(config("index.test.ts", 'amd'));
configs.push(config("index.test.js", 'amd'));
}
return configs;
}

// export default packages.flatMap(configsFor);
export default configsFor('core');
export default packages.flatMap(configsFor);
Loading

0 comments on commit b299474

Please sign in to comment.