Skip to content

Commit

Permalink
refactor(tests): convert to TypeScript
Browse files Browse the repository at this point in the history
Closes #293.
Fixes #509.
  • Loading branch information
mightyiam committed Dec 26, 2019
1 parent 2ada1f5 commit a1670f4
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 239 deletions.
1 change: 1 addition & 0 deletions .ecrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"^es/",
"^helpers/",
"^modules/",
"^test/",
"^h.d.ts",
"^h.js",
"^h.js.map",
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
/es/modules/style.d.ts
/es/modules/style.js
/es/modules/style.js.map
/es/test/
/es/h.d.ts
/es/h.js
/es/h.js.map
Expand Down Expand Up @@ -92,6 +93,7 @@
/modules/style.d.ts
/modules/style.js
/modules/style.js.map
/test/
/h.d.ts
/h.js
/h.js.map
Expand Down
13 changes: 4 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(config) {
basePath: '.',
frameworks: ['mocha', 'karma-typescript'],
// list of files / patterns to load in the browser
files: [{pattern: 'src/**/*.ts'}, {pattern: 'test/**/*'}],
files: [{pattern: 'src/**/*.ts'}],
plugins: [
'karma-mocha',
'karma-chrome-launcher',
Expand All @@ -29,8 +29,7 @@ module.exports = function(config) {
],
hostname: ci ? ip : 'localhost',
preprocessors: {
'src/**/*.ts': ['karma-typescript'],
'test/**/*.{js,ts,tsx}': ['karma-typescript'],
'src/**/*.{ts,tsx}': ['karma-typescript']
},
browserStack: {
name: 'Snabbdom',
Expand All @@ -43,16 +42,12 @@ module.exports = function(config) {
customLaunchers: browserstack,
karmaTypescriptConfig: {
coverageOptions: {
exclude: /test\//,
},
compilerOptions: {
allowJs: true,
declaration: false
exclude: /^src{\/|\\}test{\/|\\}/,
},
tsconfig: './tsconfig.json',
include: {
mode: 'merge',
values: ['test/**/*'],
values: ['src/test/**/*'],
},
},
reporters: ['dots', 'karma-typescript', 'BrowserStack'],
Expand Down
39 changes: 24 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"devDependencies": {
"@types/assert": "^1.4.3",
"@types/lodash.shuffle": "^4.2.6",
"@types/mocha": "^5.2.7",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"benchmark": "^2.1.4",
Expand All @@ -22,7 +23,6 @@
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"fake-raf": "1.0.1",
"gulp": "^3.9.1",
"gulp-clean": "^0.3.2",
"gulp-rename": "^1.2.2",
Expand All @@ -35,7 +35,7 @@
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-typescript": "^3.0.13",
"knuth-shuffle": "^1.0.1",
"lodash.shuffle": "^4.2.0",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.5",
"remark-cli": "^7.0.1",
Expand Down
20 changes: 11 additions & 9 deletions test/attachto.js → src/test/attachto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var assert = require('assert');
var snabbdom = require('../snabbdom');
import assert from 'assert'
import { init } from '../snabbdom'
import { RemoveHook } from '../hooks';

var patch = snabbdom.init([]);
var attachTo = require('../helpers/attachto').default;
var h = require('../h').default;
var patch = init([]);
import attachTo from '../helpers/attachto'
import h from '../h'

describe('attachTo', function() {
var elm, vnode0;
var elm: any, vnode0: any;
beforeEach(function() {
elm = document.createElement('div');
vnode0 = elm;
Expand Down Expand Up @@ -76,9 +77,10 @@ describe('attachTo', function() {
assert.equal(elm.children.length, 1);
});
it('remove hook receives real element', function() {
function rm(vnode, cb) {
assert.equal(vnode.elm.tagName, 'DIV');
assert.equal(vnode.elm.innerHTML, 'First text');
const rm: RemoveHook = (vnode, cb) => {
const elm = vnode.elm as HTMLDivElement;
assert.equal(elm.tagName, 'DIV');
assert.equal(elm.innerHTML, 'First text');
cb();
}
var vnode1 = h('div', [
Expand Down
18 changes: 9 additions & 9 deletions test/attributes.js → src/test/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var assert = require('assert');

var snabbdom = require('../snabbdom');
var patch = snabbdom.init([
require('../modules/attributes').default,
import assert from 'assert'
import { init } from '../snabbdom'
import attributesModule from '../modules/attributes'
var patch = init([
attributesModule
]);
var h = require('../h').default;
import h from '../h'

describe('attributes', function() {
var elm, vnode0;
var elm: any, vnode0: any;
beforeEach(function() {
elm = document.createElement('div');
vnode0 = elm;
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('attributes', function() {
assert.strictEqual(elm.getAttribute('selected'), '');
});
it('are not omitted when falsy values are provided', function() {
var vnode1 = h('div', {attrs: {href: null, minlength: 0, value: '', title:'undefined'}});
var vnode1 = h('div', {attrs: {href: null as any, minlength: 0, value: '', title:'undefined'}});
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.getAttribute('href'), 'null');
assert.strictEqual(elm.getAttribute('minlength'), '0');
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('attributes', function() {
assert.strictEqual(elm.getAttribute('required'), null);
});
it('is not omitted if the value is falsy but casted to string', function() {
var vnode1 = h('div', {attrs: {readonly: 0, noresize: null}});
var vnode1 = h('div', {attrs: {readonly: 0, noresize: null as any}});
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.getAttribute('readonly'), '0');
assert.strictEqual(elm.getAttribute('noresize'), 'null');
Expand Down

0 comments on commit a1670f4

Please sign in to comment.