Skip to content

Commit

Permalink
Merge pull request #1 from e-hein/feature/test-in-typescript-requirejs
Browse files Browse the repository at this point in the history
Feature/test in typescript requirejs
  • Loading branch information
e-hein authored Jun 30, 2020
2 parents b61ef6a + 33e88c0 commit 3b7dfc5
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 117 deletions.
6 changes: 5 additions & 1 deletion test/in-plain-html-js/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ module.exports = function(config) {

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
logLevel: config.LOG_WARN,

browserConsoleLogOptions: {
terminal: false,
},


// enable / disable watching file and executing tests whenever any file changes
Expand Down
21 changes: 15 additions & 6 deletions test/in-plain-html-js/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('interactive demo', () => {
it('should move cursor before "c"', () => {
expect(firstInput.selectionStart).toBe(2, 'start');
expect(firstInput.selectionEnd).toBe(2, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});

Expand All @@ -121,7 +121,7 @@ describe('interactive demo', () => {
it('should move cursor to the beginning', () => {
expect(firstInput.selectionStart).toBe(0, 'start');
expect(firstInput.selectionEnd).toBe(0, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});

Expand All @@ -137,7 +137,7 @@ describe('interactive demo', () => {
it('should move cursor behind "b"', () => {
expect(firstInput.selectionStart).toBe(2, 'start');
expect(firstInput.selectionEnd).toBe(2, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});

Expand All @@ -148,7 +148,7 @@ describe('interactive demo', () => {
it('should move cursor to the end', () => {
expect(firstInput.selectionStart).toBe(3, 'start');
expect(firstInput.selectionEnd).toBe(3, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});

Expand All @@ -160,7 +160,7 @@ describe('interactive demo', () => {
expect(firstInput.value).toBe('bc', 'value');
expect(firstInput.selectionStart).toBe(0, 'start');
expect(firstInput.selectionEnd).toBe(0, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});

Expand All @@ -172,7 +172,7 @@ describe('interactive demo', () => {
expect(firstInput.value).toBe('ac', 'value');
expect(firstInput.selectionStart).toBe(1, 'start');
expect(firstInput.selectionEnd).toBe(1, 'end');
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/, 'direction'));
expect(firstInput.selectionDirection).toEqual(jasmine.stringMatching(/none|forward/), 'direction');
});
});
});
Expand All @@ -187,6 +187,15 @@ describe('interactive demo', () => {
it('should *not* show control backspace', () => expect(testElement(id.control.backspace).offsetHeight).toBe(0));
it('should show control delete', () => expect(testElement(id.control.delete).offsetHeight).toBeGreaterThan(0));

describe('twice', () => {
beforeEach(() => emulateKey.mouse.hover(testElement(id.control.shift)));

it('should show control tab', () => expect(testElement(id.control.tab).offsetHeight).toBeGreaterThan(0));
it('should *not* show control shift-tab', () => expect(testElement(id.control.shiftTab).offsetHeight).toBe(0));
it('should show control backspace', () => expect(testElement(id.control.backspace).offsetHeight).toBeGreaterThan(0));
it('should *not* show control delete', () => expect(testElement(id.control.delete).offsetHeight).toBe(0));
});

describe(', focus first input', () => {
let firstInput;

Expand Down
2 changes: 1 addition & 1 deletion test/in-plain-html-js/test/init-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function waitFor(description, test, retryDelay = [0, 1, 5, 10, 20, 100, 200, 500
const ready = test();
if (ready) return done();
if (currentTry > 3) {
console.log('css not ready (' + (currentTry + 1) + ')');
console.log(description + ' not ready (' + (currentTry + 1) + ')');
}
const delay = retryDelay[currentTry++];
if (typeof delay !== 'number') {
Expand Down
13 changes: 13 additions & 0 deletions test/in-typescript-requirejs/karma-proxies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const karmaProxies = {
'/base/emulate-tab.js': '/base/node_modules/emulate-tab/dist/bundles/emulate-tab.amd.js',
'/base/emulate-key-in-browser.js': '/base/node_modules/emulate-key-in-browser/dist/bundles/emulate-key-in-browser.amd.js',
'/base/tslib.js': '/base/node_modules/tslib/tslib.js',
'/assets/': '/base/dist/assets/',
'/scripts/': '/base/src/',
'/styles/': '/base/src/',
'/app/': 'http://localhost:4300/',
};

if (typeof module !== 'undefined') {
module.exports = karmaProxies;
}
55 changes: 23 additions & 32 deletions test/in-typescript-requirejs/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Karma configuration
// Generated on Thu Jun 18 2020 08:31:24 GMT+0200 (GMT+02:00)
// Generated on Tue Jun 30 2020 12:52:45 GMT+0200 (GMT+02:00)

const withCoverage = true && process.env.COVERAGE;
const tsConfig = require('./tsconfig.json');

module.exports = function(config) {
console.log('orig config', config);
tsConfig.compilerOptions.module = 'amd';
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
Expand All @@ -11,42 +14,28 @@ module.exports = function(config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'fixture', 'karma-typescript'],
frameworks: ['jasmine', 'requirejs', 'fixture', 'karma-typescript'],
karmaTypescriptConfig: {
...require('./tsconfig.json'),
...tsConfig,
coverageOptions: {
instrumentation: false
instrumentation: withCoverage
}
},

plugins: [
'karma-fixture',
'karma-typescript',
'karma-jasmine',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine-html-reporter',
'karma-mocha-reporter',
// require('karma-coverage-istanbul-reporter'),
'karma-html2js-preprocessor',
],

// list of files / patterns to load in the browser
files: [
{ pattern: 'node_modules/requirejs/require.js', included: false, watched: false },
{ pattern: 'dist/assets/*.*', included: false },
{ pattern: 'src/**/*.html', included: true },
{ pattern: 'src/**/*.ts', included: false },
{ pattern: 'src/**/*.css', included: false },
'src/**/*.html',
'src/**/*.@(spec|model|controller).@(ts|js)',
{ pattern: 'dist/assets/*.*', included: false },
{ pattern: 'node_modules/emulate-key-in-browser/dist/bundles/emulate-key-in-browser.amd.js', included: false },
{ pattern: 'node_modules/emulate-tab/dist/bundles/emulate-tab.amd.js', included: false },
{ pattern: 'node_modules/tslib/tslib.js', included: false },
'karma-proxies.js',
'test-main.js',
],

proxies: {
'/assets/': '/base/dist/assets/',
'/scripts/require.js': '/base/node_modules/requirejs/require.js',
'/scripts/': '/base/src/',
'/styles/': '/base/src/',
'/app/': 'http://localhost:4300/',
},
proxies: require('./karma-proxies'),

// list of files / patterns to exclude
exclude: [
Expand All @@ -56,10 +45,8 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
...config.preprocessors,
'**/*.js': [],
'**/*.html': ['html2js'],
"**/*.ts": "karma-typescript" // *.tsx for React Jsx
"**/*.ts": "karma-typescript",
},

// test results reporter to use
Expand All @@ -81,7 +68,11 @@ module.exports = function(config) {

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
logLevel: config.LOG_WARN,

browserConsoleLogOptions: {
terminal: false,
},


// enable / disable watching file and executing tests whenever any file changes
Expand Down
10 changes: 4 additions & 6 deletions test/in-typescript-requirejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
"description": "test emulate-key-in-browser in typescript with requirejs",
"main": "test.js",
"scripts": {
"prebuild": "npm i ../../tmp/emulate-key-in-browser.latest.tgz",
"build": "DEBUG=demo-build* node build.js",
"prestart": "npm run build",
"start": "node -r ts-node/register src/app.ts",
"start_watch": "npm-watch start",
"test": "karma start",
"install-emulate-key-in-browser": "npm i ../../tmp/emulate-key-in-browser.latest.tgz",
"uninstall-emulate-key-in-browser": "npm i ../../tmp/emulate-key-in-browser.latest.tgz",
"reinstall-emulate-key-in-browser": "npm run uninstall-emulate-key-in-browser",
"postreinstall-emulate-key-in-browser": "npm run install-emulate-key-in-browser",
"precoverage": "npm run reinstall-emulate-key-in-browser",
"coverage": "karma start --browsers=ChromeHeadless,FirefoxHeadless --single-run"
"precoverage": "npm run build",
"coverage": "COVERAGE=true karma start --browsers=ChromeHeadless,FirefoxHeadless --single-run"
},
"watch": {
"start": {
Expand Down Expand Up @@ -44,6 +41,7 @@
"karma-jasmine": "^3.3.1",
"karma-jasmine-html-reporter": "^1.5.4",
"karma-mocha-reporter": "^2.2.5",
"karma-requirejs": "^1.1.0",
"karma-typescript": "^5.0.3",
"npm-watch": "^0.6.0",
"ts-node": "^8.10.2",
Expand Down
4 changes: 2 additions & 2 deletions test/in-typescript-requirejs/src/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventCheckController } from "./event-check.controller";
import { waitFor } from './wait-for.model';
import { waitFor } from './wait-for.controller';

xdescribe('demo app', () => {
let appFrame: HTMLIFrameElement;
Expand All @@ -19,7 +19,7 @@ xdescribe('demo app', () => {
appFrame.style.height = '100vh';
const loadedListener = () => {
appFrame.removeEventListener('load', loadedListener);
waitFor('event check', () => !!(eventCheck = appFrame.contentWindow['eventCheck']), 100, 20).then(done);
waitFor('event check', () => !!(eventCheck = appFrame.contentWindow['eventCheck'])).then(done);
};
appFrame.addEventListener('load', loadedListener);
fixture.el.appendChild(appFrame);
Expand Down
Loading

0 comments on commit 3b7dfc5

Please sign in to comment.