Skip to content
Permalink
Browse files

Fixed the testing

  • Loading branch information
alannawalton committed Aug 17, 2017
1 parent 0503a2c commit f9968fa7d6a1c71e80821cab63c6492370162563
Showing with 45 additions and 35 deletions.
  1. +9 −0 gulpfile.js
  2. +3 −0 package.json
  3. +2 −3 readiness-tool/vendors.json
  4. +31 −32 tests/popup-test.js
@@ -15,10 +15,19 @@
*/

const gulp = require('gulp');
const gutil = require('gulp-util');
const Karma = require('karma').Server;
const karmaDefault = require('./karma.conf');


gulp.task('test', function(done) {
try {
require('./readiness-tool/vendors.json');
console.log("vendors.json was found with no problems");
} catch (err){
gutil.log(gutil.colors.red('vendors.json failed to load because this error: ' + err.message));
return;
}
new Karma(karmaDefault, function(exitCode) {
$$.util.log($$.util.colors.yellow(
'Shutting down test responses server on localhost:31862'));
@@ -26,7 +26,10 @@
"graceful-fs": "^4.1.3",
"handlebars": "^4.0.5",
"http-status": "^0.2.2",
"is-valid-json": "^1.0.2",
"jshint": "^2.9.1",
"jsonschema": "^1.1.1",
"karma-read-json": "^1.1.0",
"material-design-lite": "^1.1.3",
"microdata-node": "^0.2.1",
"node-fetch": "^1.5.3",
@@ -26,8 +26,7 @@
"regex": [
"(?:adriver\\.core\\.\\d\\.js|https?://(?:content|ad|masterh\\d)\\.adriver\\.ru/)",
"(?:<embed[^>]+(?:src=\"https?://mh\\d?\\.adriver\\.ru/|flashvars=\"[^\"]*(?:http:%3A//(?:ad|mh\\d?)\\.adriver\\.ru/|adriver_banner))|<(?:(?:iframe|img)[^>]+src|a[^>]+href)=\"https?://ad\\.adriver\\.ru/)"
],
"website": "http://adriver.ru"
]
},
"AdRoll": {
"category": "Ads",
@@ -564,7 +563,7 @@
"category": "Ads",
"html": [
"<img [^>]*src=\"[^\"]+ad\\.zanox\\.com",
"zanox\\.com/scripts/zanox\\.js$"
"zanox\\.com/scripts/zanox\\.js$",
]
},
"comScore": {
@@ -17,6 +17,11 @@ const popup = require('../readiness-tool/popup');

const vendors = require('../readiness-tool/vendors');

const isJSON = require('is-valid-json');

const Validator = require('jsonschema').Validator;

const v = new Validator();

describe('isSupported(key)', function () {

@@ -72,40 +77,34 @@ describe('addToDict(tempScript, htmlString, foundThis, key, category)', function
});


const loadJSON = (callback) => {
let xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'my_data.json', true);
// Replace 'my_data' with the path to your file
xobj.onreadystatechange = () => {
if (xobj.readyState === 4 && xobj.status === "200") {
// Required use of an anonymous callback
// as .open() will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
describe('vendors.json should be valid json', function () {

it('should be a valid file', function () {

const vendorSchema = {
'id': '/SimpleVendors',
'type': 'object',
'properties': {
'regex': {
'type': 'array',
'items': {
'type': 'string'
}
},
'tooltip': {
'type': 'string'
},
'category': {
'type': 'string'
},
},
'required': ['category', 'regex']
};
xobj.send(null);
}

v.addSchema(vendorSchema, '/SimpleVendors');
const result = v.validate(vendors.vendor, vendorSchema);

describe('vendors.json should be valid json', function () {

beforeEach(() => {
sinon.stub(window, 'fetch');
});

afterEach(() => {
window.fetch.restore();
});

it('should be a valid file', function () {
fetch('../readiness-tool/vendors')
.then(function(response) {
console.log('response', response);
console.log('response text', response.text);

}).catch(function(err) {
// Error :(
});
expect(isJSON(vendors)).to.be.true;
expect(result.valid).to.be.true;
});
});

0 comments on commit f9968fa

Please sign in to comment.
You can’t perform that action at this time.