forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Berkeley Martinez
authored and
Berkeley Martinez
committed
Jul 29, 2016
1 parent
1db5caa
commit 9b7bd2a
Showing
24 changed files
with
473 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
} | ||
}, | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"mocha": true, | ||
"node": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var common = parent.__common; | ||
var Rx = parent.Rx; | ||
|
||
common.getJsOutput = function evalJs(source = '') { | ||
if (window.__err || !common.shouldRun()) { | ||
return window.__err || 'source disabled'; | ||
} | ||
let output; | ||
try { | ||
/* eslint-disable no-eval */ | ||
output = eval(source); | ||
/* eslint-enable no-eval */ | ||
} catch (e) { | ||
window.__err = e; | ||
} | ||
return output; | ||
}; | ||
|
||
common.runTests$ = function runTests$({ tests = [], source }) { | ||
const editor = { getValue() { return source; } }; | ||
if (window.__err) { | ||
return Rx.Observable.throw(window.__err); | ||
} | ||
|
||
// Iterate through the test one at a time | ||
// on new stacks | ||
return Rx.Observable.from(tests, null, null, Rx.Scheduler.default) | ||
// add delay here for firefox to catch up | ||
.delay(100) | ||
.map(({ text, testString }) => { | ||
const newTest = { text, testString }; | ||
let test; | ||
try { | ||
/* eslint-disable no-eval */ | ||
test = eval(testString); | ||
/* eslint-enable no-eval */ | ||
if (typeof test === 'function') { | ||
// maybe sync/promise/observable | ||
if (test.length === 0) { | ||
test(); | ||
} | ||
// callback test | ||
if (test.length === 1) { | ||
console.log('callback test'); | ||
} | ||
} | ||
} catch (e) { | ||
newTest.err = e.message.split(':').shift(); | ||
} | ||
return newTest; | ||
}) | ||
// gather tests back into an array | ||
.toArray(); | ||
}; | ||
|
||
// used when updating preview without running tests | ||
common.checkPreview$ = function checkPreview$(args) { | ||
if (window.__err) { | ||
return Rx.Observable.throw(window.__err); | ||
} | ||
return Rx.Observable.just(args); | ||
}; | ||
|
||
// now that the runPreviewTest$ is defined | ||
// we set the subject to true | ||
// this will let the updatePreview | ||
// script now that we are ready. | ||
common.testFrameReady$.onNext(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Observable } from 'rx'; | ||
import loopProtect from 'loop-protect'; | ||
|
||
loopProtect.hit = function hit(line) { | ||
var err = 'Error: Exiting potential infinite loop at line ' + | ||
line + | ||
'. To disable loop protection, write: \n\\/\\/ noprotect\nas the first' + | ||
'line. Beware that if you do have an infinite loop in your code' + | ||
'this will crash your browser.'; | ||
console.error(err); | ||
}; | ||
|
||
const transformersForHtmlJS = { | ||
ext: /html|js/, | ||
transformers: [ | ||
{ | ||
name: 'add-loop-protect', | ||
transformer: function addLoopProtect(file) { | ||
file.contents = loopProtect(file.contents); | ||
return file; | ||
} | ||
} | ||
] | ||
}; | ||
|
||
|
||
// Observable[Observable[File]]::addLoopProtect() => Observable[String] | ||
export default function transformers() { | ||
const source = this; | ||
return source.map(files$ => files$.flatMap(file => { | ||
if (!transformersForHtmlJS.ext.test(file.ext)) { | ||
return Observable.just(file); | ||
} | ||
return Observable.from(transformersForHtmlJS.transformers) | ||
.reduce((file, context) => context.transformer(file), file); | ||
})); | ||
} |
Oops, something went wrong.