Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created November 3, 2015 13:25
Show Gist options
  • Save jlongster/0485f3277d47f4018bbc to your computer and use it in GitHub Desktop.
Save jlongster/0485f3277d47f4018bbc to your computer and use it in GitHub Desktop.
var Immutable = require('devtools/client/shared/vendor/seamless-immutable');
var gentest = require('devtools/client/shared/vendor/gentest');
var types = gentest.types;
function maybe(type) {
return types.oneOf([type, types.constantly(null)]);
}
var foo = function () {
var x = 5;
var y = 6;
return x + y;
}.toString();
var bar = function(x, y) {
if(Math.random() < .5) {
return Math.floor(x / y);
}
return x / y;
}.toString();
var baz = function (actor) {
var source = getSource(actor);
if(source.url) {
addSourc(source);
}
}.toString();
var SourceText = gentest.types.shape({
loading: types.bool,
error: types.constantly(null),
text: types.elements([
foo,
bar,
baz,
foo + '\n\n' + bar,
foo + '\n\n' + baz,
foo + '\n\n' + bar + '\n\n' + baz
]),
contentType: types.string
});
var SourceType = gentest.types.shape({
actor: gentest.types.suchThat(s => s.length > 0, types.string),
url: gentest.types.suchThat(s => s.length > 0, types.string),
addonID: maybe(types.string),
addonPath: maybe(types.string),
isBlackBoxed: types.oneOf([types.bool, types.constantly(false)]),
isPrettyPrinted: types.bool,
introductionUrl: maybe(types.string),
introductionType: maybe(types.string)
});
var SourceOpts = gentest.types.shape({
line: types.int.nonNegative,
charOffset: maybe(types.int.nonNegative),
lineOffset: maybe(types.int.nonNegative),
moveCursor: maybe(types.bool),
debugHighlight: maybe(types.bool)
})
var SourceMap = gentest.types.fmap(sources => {
const obj = {};
for(let s of sources) {
obj[s.actor] = s;
}
return obj;
}, gentest.types.arrayOf(SourceType));
var SourceState = gentest.types.bind(SourceMap, sources => {
var allSources = Object.keys(sources).map(k => sources[k]);
return gentest.types.tuple([
gentest.types.constantly(sources),
allSources.length ? maybe(gentest.types.elements(allSources)) : gentest.types.constantly(null),
SourceOpts,
gentest.types.fmap(textInfo => {
const obj = {};
textInfo.forEach((v, i) => {
if(i < allSources.length) {
obj[allSources[i].actor] = v;
}
});
return obj;
}, gentest.types.arrayOf(SourceText))
]);
});
var sourceStateProp = gentest.Property.forAll([SourceState], 'it renders', state => {
var sourceState = Immutable({
sources: state[0],
selectedSource: state[1] ? state[1].actor : null,
selectedSourceOpts: state[2],
sourcesText: state[3]
});
var sourceClients = Object.keys(state[0]).map(k => {
var source = state[0][k];
var sourceText = state[3][source.actor];
return new MockSourceClient(gThreadClient, {
url: source.url,
actor: source.actor
}, {
source: sourceText ? sourceText.text : 'NO TEXT',
contentText: sourceText ? sourceText.contentType : ''
})
})
DebuggerController.activeThread._mockInit(sourceClients);
stateUtils.replaceState(
Object.assign({}, stateUtils.getState(), { sources: sourceState })
);
return true;
});
gentest.AsyncRunner(sourceStateProp, {
numTests: 100,
maxSize: 50
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment