-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
t/1: Introduce tests and Bender.js #11
Changes from 9 commits
118a4eb
ffe17c5
e7e9834
09fa91e
c9ad4d0
5aa7d5a
dd79ce5
2946304
47cde86
87f8200
19e29d0
6488116
0c63b0a
ebcbd4e
758b958
26f6c7c
41ec3ce
70373f7
1137ff7
a7f512d
907ef34
af63433
a8afa0a
338f468
c15dbcd
938c8d9
6bf8aa1
61c5f9c
0de6f6b
a60cb57
a530d20
0968169
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* jshint browser: false, node: true */ | ||
|
||
'use strict'; | ||
|
||
var config = { | ||
plugins: [ | ||
// Uncomment to enable code coverage. | ||
// 'benderjs-coverage', | ||
|
||
'benderjs-mocha', | ||
'benderjs-chai', | ||
'dev/bender/plugins/ckeditor5' | ||
], | ||
|
||
framework: 'mocha', | ||
|
||
applications: { | ||
ckeditor: { | ||
path: '.', | ||
files: [ | ||
'node_modules/requirejs/require.js', | ||
'ckeditor.js' | ||
] | ||
} | ||
}, | ||
|
||
tests: { | ||
all: { | ||
applications: [ 'ckeditor' ], | ||
paths: [ | ||
'tests/**', | ||
'node_modules/ckeditor5-*/tests/**' | ||
] | ||
} | ||
}, | ||
|
||
coverage: { | ||
paths: [ | ||
'ckeditor.js', | ||
'src/**/*.js', | ||
'node_modules/ckeditor5-*/src/**/*.js' | ||
] | ||
} | ||
}; | ||
|
||
module.exports = config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* jshint node: true */ | ||
|
||
'use strict'; | ||
|
||
var path = require( 'path' ); | ||
var files = [ | ||
path.join( __dirname, '../static/extensions.js' ) | ||
]; | ||
|
||
module.exports = { | ||
name: 'bender-framework-ckeditor5', | ||
|
||
files: files, | ||
include: files | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "benderjs-ckeditor5", | ||
"description": "CKEditor 5 plugin for Bender.js", | ||
"main": "lib/index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals bender, CKEDITOR */ | ||
|
||
'use strict'; | ||
|
||
( function() { | ||
// Override bender.start to wait until the "ckeditor" module is ready. | ||
var originalStart = bender.start; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just because defer() wasn't still available when I wrote it :) I'll change it. |
||
bender.start = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we discussed this already, but I think we should consider adding some space between the variable definition and the rest of the code. It would improve the readability of the code because right now it looks a bit crammed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 and in this case it also matches the "margin around blocks" rule that we agreed on. |
||
CKEDITOR.require( [ 'ckeditor' ], function() { | ||
originalStart.apply( this, arguments ); | ||
} ); | ||
}; | ||
} )(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals describe, it, expect, CKEDITOR */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're gonna have describe, it and expect in every test, maybe we can "globalize" them in a single place, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i tried this already but it doesn't work in the way we're using jshint right now (by pointing to a specific configuration file). If we would like to do it it looks like we would have to bloat (further) the root by adding . jshintrc there (and at this point .jscs) as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh... I've been already thinking about this too. I think that the easiest (thus, doable) solutions are:
In CKEditor 4 we use now the second approach and it's ok. For instance, you never use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gonna have an issue for this once this PR gets merged. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reported #13. |
||
|
||
'use strict'; | ||
|
||
CKEDITOR.define( 'testModule', [ 'ckeditor' ], function( ckeditor ) { | ||
return { | ||
test: ( typeof ckeditor == 'object' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeof null == 'object' Touché! |
||
}; | ||
} ); | ||
|
||
describe( 'amd', function() { | ||
it( 'require() should work with defined module', function( done ) { | ||
CKEDITOR.require( [ 'testModule' ], function( testModule ) { | ||
expect( testModule ).to.have.property( 'test' ).to.be.true(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary empty line (I know I'm bit*hing right now, but I think this should be consistent across our tests). |
||
done(); | ||
} ); | ||
} ); | ||
|
||
it( 'require() should work with core module', function( done ) { | ||
CKEDITOR.require( [ 'utils' ], function( utils ) { | ||
expect( utils ).to.be.an( 'object' ); | ||
done(); | ||
} ); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals beforeEach, describe, it, expect, CKEDITOR, window, document */ | ||
|
||
'use strict'; | ||
|
||
beforeEach( function() { | ||
// Ensure that no CKEDITOR_BASEPATH global is available. | ||
delete window.CKEDITOR_BASEPATH; | ||
|
||
// Remove all script elements from the document. | ||
removeScripts(); | ||
} ); | ||
|
||
describe( 'ckeditor.basePath', function() { | ||
it( 'Full URL', function( done ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name of the test case is obscure. It should be written using natural language, e.g. "Full URL should do something". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please review all the test case titles - I don't want to comment every single one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm reviewing them right now and in fact it makes much more sense. We must also get used to use describe() properly. |
||
CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) { | ||
addScript( 'http://bar.com/ckeditor/ckeditor.js' ); | ||
expect( CKEDITOR._getBasePath() ).equals( 'http://bar.com/ckeditor/' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hum, in fact there are many possible variations: We may agree on best practices, but in any case I think we should not enforce this because it'll be a pain in the ass for contributors to have their stuff rejected because of such things, considering that chai gives all these possibilities and they're all right. I'll change what we have now to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, which is better: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The one that is grammatically correct :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember we've been talking about using the shortest (or reasonably short) versions. Apart from grammatical correctness, I wouldn't like to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually to make it right, it should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Reinmar, we use I'll make the change and lets see how it looks like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I know, but while writing my comment I noticed that it's not going through my fingers too well :P Anyway - |
||
done(); | ||
} ); | ||
} ); | ||
|
||
it( 'CKEDITOR_BASEPATH', function( done ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) { | ||
window.CKEDITOR_BASEPATH = 'http://foo.com/ckeditor/'; | ||
expect( CKEDITOR._getBasePath() ).equals( 'http://foo.com/ckeditor/' ); | ||
done(); | ||
} ); | ||
} ); | ||
|
||
it( 'Ensure that no browser keep script URLs absolute or relative', function( done ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// Browsers should convert absolute and relative URLs to full URLs. | ||
// If this test fails in any browser, _getBasePath() must be reviewed to deal with such case (v4 does it). | ||
|
||
test( '/absolute/url/ckeditor.js' ); | ||
test( '../relative/url/ckeditor.js' ); | ||
|
||
done(); | ||
|
||
function test( url ) { | ||
removeScripts(); | ||
|
||
var script = addScript( url ); | ||
|
||
// Test if the src now contains '://'. | ||
expect( /:\/\//.test( script.src ) ).to.be.true(); | ||
} | ||
} ); | ||
} ); | ||
|
||
function addScript( url ) { | ||
var script = document.createElement( 'script' ); | ||
script.src = url; | ||
document.head.appendChild( script ); | ||
|
||
return script; | ||
} | ||
|
||
function removeScripts() { | ||
var scripts = [].slice.call( document.getElementsByTagName( 'script' ) ); | ||
var script; | ||
|
||
while ( ( script = scripts.shift() ) ) { | ||
script.parentNode.removeChild( script ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/* globals describe, it, expect, CKEDITOR */ | ||
|
||
'use strict'; | ||
|
||
describe( 'ckeditor', function() { | ||
it( 'getPluginPath() with development source code', function( done ) { | ||
CKEDITOR.require( [ 'ckeditor' ], function( CKEDITOR ) { | ||
var basePath = CKEDITOR.basePath; | ||
var path = CKEDITOR.getPluginPath( 'test' ); | ||
|
||
if ( CKEDITOR.isDev ) { | ||
expect( path ).equals( basePath + 'node_modules/ckeditor-plugin-test/src/' ); | ||
} else { | ||
expect( path ).equals( basePath + 'plugins/test/' ); | ||
} | ||
done(); | ||
} ); | ||
} ); | ||
|
||
it( 'getPluginPath() with production code', function( done ) { | ||
CKEDITOR.require( [ 'ckeditor', 'ckeditor-core' ], function( CKEDITOR, core ) { | ||
// To be able to run this test on both dev and production code, we need to override getPluginPath with the | ||
// core version of it and restore it after testing. | ||
var originalGetPluginPath = CKEDITOR.getPluginPath; | ||
CKEDITOR.getPluginPath = core.getPluginPath; | ||
|
||
// This test is good for both the development and production codes. | ||
var basePath = CKEDITOR.basePath; | ||
var path = CKEDITOR.getPluginPath( 'test' ); | ||
|
||
expect( path ).equals( basePath + 'plugins/test/' ); | ||
|
||
CKEDITOR.getPluginPath = originalGetPluginPath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not going to be executed if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch... I've just pushed a fix for it by simply reverting the override before the assertion. |
||
|
||
done(); | ||
} ); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
framework
is no longer neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 0de6f6b.