karma-iframes
Advanced tools
Comparing version
exports['framework:iframes'] = ['factory', require('./lib/framework.js').IFrameFramework]; | ||
exports['middleware:iframes'] = ['factory', require('./lib/middleware.js')]; | ||
exports['middleware:iframes-rewrite'] = ['factory', require('./lib/rewrite-middleware.js')]; | ||
exports['middleware:iframes-serve-file'] = ['factory', require('./lib/serve-file-middleware.js').createStaticFileMiddleware]; | ||
exports['preprocessor:iframes'] = ['factory', require('./lib/preprocessor.js')]; |
@@ -9,16 +9,14 @@ let fs = require('fs'); | ||
let transformedContextDir = require('tmp').dirSync().name; | ||
let nonIncludedFiles = []; | ||
function clone(obj) { | ||
return Object.assign({}, obj); | ||
} | ||
function IFrameFramework(files, preprocessors, config, logger) { | ||
let log = logger.create('framework:iframes'); | ||
// Install middleware that transforms the output | ||
// Install middleware that transforms the iframe context HTML | ||
config.beforeMiddleware = config.beforeMiddleware || []; | ||
config.beforeMiddleware.push('iframes'); | ||
config.beforeMiddleware.push('iframes-rewrite'); | ||
// Install middleware that serves the original sources before transformation | ||
config.middleware = config.middleware || []; | ||
config.middleware.push('iframes-serve-file'); | ||
@@ -25,0 +23,0 @@ files.forEach(file => { |
@@ -5,2 +5,4 @@ let fs = require('fs'); | ||
let {TMP_STATIC_FILES_DIR, STATIC_PREFIX} = require('./serve-file-middleware.js'); | ||
function IFramePreprocessor(logger) { | ||
@@ -14,2 +16,4 @@ let log = logger.create('preprocessor:iframes'); | ||
let transformedFilePath = file.originalPath.replace(/(\/|\\)/g, '_') + '.js'; | ||
let template = TEMPLATE | ||
@@ -19,12 +23,16 @@ // Add token that the middleware can replace with the path to the reverse-context.js script | ||
// Inline the test script into the page | ||
// FIXME: 1. This does not preserve the script order but inserts the script always at the end | ||
// FIXME: 2. This might break with scripts that contain the `</script>` or `!]]` tokens. | ||
// FIXME: This does not preserve the script order but inserts the script always at the end | ||
.replace('%SCRIPTS%', ` | ||
%SCRIPTS% | ||
<script type="text/javascript"><!--//--><![CDATA[//><!-- | ||
${content} | ||
//--><!]]></script> | ||
<script type="text/javascript" src="${STATIC_PREFIX}${transformedFilePath}"></script> | ||
`); | ||
// Save the file contents to the temp dir for serving it later | ||
fs.writeFile(`${TMP_STATIC_FILES_DIR}/${transformedFilePath}`, content, (err) => { | ||
if(err) { | ||
log.error('Error writing file befor transformation', err); | ||
} | ||
done(template); | ||
}); | ||
done(template); | ||
}; | ||
@@ -31,0 +39,0 @@ } |
{ | ||
"name": "karma-iframes", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Lets you run each test in a separate context, loaded as an iframe.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -87,3 +87,3 @@ // jshint es3: false | ||
result.suite = result.suite || []; | ||
result.suite.unshift(this.fileName); | ||
result.suite.unshift(this.fileName.replace(/\.iframe\.html$/, '')); | ||
result.id = this.fileName+'#'+(result.id || ''); | ||
@@ -90,0 +90,0 @@ this.finished++; |
// Mock the __karma__ to be used inside the iframe | ||
// Send progress to the parent frame for iframes-adapter to send to the real __karma__ of the real context | ||
window.__karma__ = (function() { | ||
window.__karma__ = (function(hasParent) { | ||
if(!hasParent) { | ||
// Someone has opened this frame manually → inject the normal context.js | ||
document.write('<script src="/context.js" type="application/javascript"></script>'); | ||
document.write('<script src="/debug.js" type="application/javascript"></script>'); | ||
return window.__karma__; | ||
} | ||
function UNIMPLEMENTED_START() { | ||
@@ -13,3 +20,3 @@ throw new Error('An adapter should provide the start function'); | ||
}; | ||
function callParentKarmaMethod(methodName, args) { | ||
@@ -23,3 +30,3 @@ args.unshift('iframe-test-results', methodName); | ||
} | ||
DIRECT_METHODS = ['error', 'log', 'complete', 'result']; | ||
@@ -77,2 +84,2 @@ DIRECT_METHODS.forEach(method => { | ||
return karma; | ||
})(); | ||
})(window.parent !== window); |
61924
4.44%12
20%546
9.86%3
50%