Skip to content

Commit

Permalink
Merge branch 'GPII-3553'
Browse files Browse the repository at this point in the history
* GPII-3553:
  GPII-3553: Added tests for "check required options" grade.
  GPII-3553: Added note about work required to collect complete code coverage data.
  GPII-3553: Exclude test files from reports.
  NOJIRA: Removed stale TODO.
  NOJIRA: Removed outdated .istanbul.yml file.
  NOJIRA: Routine dependency update.
  GPII-3553: Updated for compatibility with Node 10.
  GPII-3553: Added browser coverage to overall report.  Updated all dependencies.
  • Loading branch information
amb26 committed Feb 11, 2019
2 parents d02f1d1 + 9f4f117 commit e5c4e42
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage
reports
.vagrant
package-lock.json
instrumented
7 changes: 0 additions & 7 deletions .istanbul.yml

This file was deleted.

6 changes: 4 additions & 2 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"reporter": ["html", "text-summary"],
"reporter": ["none"],
"report-dir": "reports",
"temp-directory": "coverage"
"temp-dir": "coverage",
"clean": false,
"exclude": ["**/tests/**/*.js"]
}
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function (grunt) {
grunt.initConfig({
lintAll: {
sources: {
md: [ "./*.md","./**/*.md", "!./node_modules/**" ],
md: [ "./*.md","./docs/*.md"],
js: ["./src/**/*.js", "./tests/**/*.js", "./*.js"],
json: ["./src/**/*.json", "./tests/**/*.json", "./*.json"],
json5: ["./tests/**/*.json5"],
Expand Down
37 changes: 21 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
{
"name": "gpii-handlebars",
"version": "1.1.2",
"version": "1.1.3",
"private": false,
"license": "BSD-3-Clause",
"repository": "https://github.com/GPII/gpii-handlebars",
"scripts": {
"pretest": "node node_modules/rimraf/bin.js coverage/* reports/*",
"test": "node node_modules/istanbul/lib/cli.js cover tests/all-tests.js"
"test": "npm run test:node && npm run test:browser",
"test:node": "node node_modules/nyc/bin/nyc.js node tests/js/server/all-server-tests.js",
"test:browser": "node instrumented/tests/js/browser/all-browser-tests.js",
"pretest:browser": "node tests/js/lib/instrument-source.js",
"posttest": "node node_modules/nyc/bin/nyc.js report --reporter text-summary --reporter html"
},
"dependencies": {
"chokidar": "2.0.4",
"gpii-binder": "1.0.3",
"gpii-express": "1.0.14",
"handlebars": "4.0.11",
"chokidar": "2.1.0",
"gpii-binder": "1.0.4",
"gpii-express": "1.0.15",
"handlebars": "4.1.0",
"infusion": "3.0.0-dev.20180208T114206Z.2964703",
"json5": "1.0.1",
"markdown-it": "8.4.1",
"json5": "2.1.0",
"markdown-it": "8.4.2",
"md5": "2.2.1",
"underscore-node": "0.1.2"
},
"devDependencies": {
"cheerio": "1.0.0-rc.2",
"eslint": "5.1.0",
"eslint": "5.13.0",
"eslint-config-fluid": "1.3.0",
"foundation-sites": "6.4.1",
"gpii-grunt-lint-all": "1.0.1-dev.20180706T153657Z.4cbbd61",
"gpii-grunt-lint-all": "1.0.5",
"gpii-testem": "2.1.7",
"gpii-webdriver": "1.0.3-dev.20180316T104657Z.4a84a30",
"grunt": "1.0.3",
"istanbul": "0.4.5",
"kettle": "1.7.3",
"kettle": "1.10.1",
"mkdirp": "0.5.1",
"node-jqunit": "1.1.8",
"recursive-copy": "2.0.9",
"request": "2.87.0",
"rimraf": "2.6.2",
"tough-cookie": "2.4.3"
"nyc": "13.2.0",
"recursive-copy": "2.0.10",
"request": "2.88.0",
"rimraf": "2.6.3",
"tough-cookie": "3.0.1"
}
}
9 changes: 9 additions & 0 deletions tests/js/browser/all-browser-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/* eslint-env node */
"use strict";

/*
TODO: Convert these tests to use gpii-testem once this feature is added:
https://issues.gpii.net/browse/GPII-3700
*/

require("./browser-hasRequiredOptions-tests.js");
require("./browser-initBlock-tests.js");
require("./browser-inline-tests.js");
require("./browser-renderer-serverAware-tests.js");
Expand Down
80 changes: 80 additions & 0 deletions tests/js/browser/browser-hasRequiredOptions-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// TODO: This should be removed as soon as "schema-validated components" are available.
// Test "has required options" grade using `gpii-test-browser`.
//
/* eslint-env node */
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");

require("./includes.js");

fluid.registerNamespace("gpii.tests.handlebars.browser.hasRequiredOptions");

gpii.tests.handlebars.browser.hasRequiredOptions.createComponent = function (options) {
try {
gpii.tests.handlebars.hasRequiredOptions(options);
return true;
}
catch (error) {
return false;
}
};

fluid.defaults("gpii.tests.handlebars.browser.hasRequiredOptions.caseHolder", {
gradeNames: ["gpii.test.handlebars.browser.caseHolder"],
rawModules: [{
name: "Testing the `hasRequiredOptions` client-side grade...",
tests: [
{
name: "Confirm that required options are checked correctly...",
sequence: [
{
func: "{testEnvironment}.webdriver.get",
args: ["{testEnvironment}.options.url"]
},
{
event: "{testEnvironment}.webdriver.events.onGetComplete",
listener: "{testEnvironment}.webdriver.executeScript",
args: [gpii.tests.handlebars.browser.hasRequiredOptions.createComponent, {}]
},
{
event: "{testEnvironment}.webdriver.events.onExecuteScriptComplete",
listener: "jqUnit.assertEquals",
args: ["Omitting all options should result in failure.", false, "{arguments}.0"]
},
{
func: "{testEnvironment}.webdriver.executeScript",
args: [gpii.tests.handlebars.browser.hasRequiredOptions.createComponent, { skittles: true }]
},
{
event: "{testEnvironment}.webdriver.events.onExecuteScriptComplete",
listener: "jqUnit.assertEquals",
args: ["Omitting one option should result in failure.", false, "{arguments}.0"]
},
{
func: "{testEnvironment}.webdriver.executeScript",
args: [gpii.tests.handlebars.browser.hasRequiredOptions.createComponent, { beer: true, skittles: true }]
},
{
event: "{testEnvironment}.webdriver.events.onExecuteScriptComplete",
listener: "jqUnit.assertEquals",
args: ["Supplying all options should result in success.", true, "{arguments}.0"]
}
]
}
]
}]
});

fluid.defaults("gpii.tests.handlebars.browser.hasRequiredOptions.testEnvironment", {
gradeNames: ["gpii.test.handlebars.browser.environment"],
"port": 6924,
"path": "content/tests-hasRequiredOptions.html",
components: {
caseHolder: {
type: "gpii.tests.handlebars.browser.hasRequiredOptions.caseHolder"
}
}
});

gpii.test.webdriver.allBrowsers({ baseTestEnvironment: "gpii.tests.handlebars.browser.hasRequiredOptions.testEnvironment"});
2 changes: 1 addition & 1 deletion tests/js/browser/browser-initBlock-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gpii.tests.handlebars.browser.initBlock.selectorContains = function (selector, s
};

fluid.defaults("gpii.tests.handlebars.browser.initBlock.caseHolder", {
gradeNames: ["gpii.test.webdriver.caseHolder"],
gradeNames: ["gpii.test.handlebars.browser.caseHolder.base"],
rawModules: [{
name: "Testing `initBlock` helper...",
tests: [
Expand Down
2 changes: 1 addition & 1 deletion tests/js/browser/browser-inline-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ gpii.tests.handlebars.browser.inline.hasSecondaryPartial = function () {
};

fluid.defaults("gpii.tests.handlebars.browser.inline.caseHolder", {
gradeNames: ["gpii.test.webdriver.caseHolder"],
gradeNames: ["gpii.test.handlebars.browser.caseHolder.base"],
rawModules: [{
name: "Test the `inline` middleware...",
tests: [{
Expand Down
2 changes: 1 addition & 1 deletion tests/js/browser/browser-renderer-standalone-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gpii.tests.handlebars.browser.renderer.standalone.render = function (templateKey
};

fluid.defaults("gpii.tests.handlebars.browser.renderer.standalone.caseHolder", {
gradeNames: ["gpii.test.webdriver.caseHolder"],
gradeNames: ["gpii.test.handlebars.browser.caseHolder.base"],
rawModules: [{
name: "Testing standalone renderer component...",
tests: [
Expand Down
2 changes: 1 addition & 1 deletion tests/js/browser/browser-templateFormControl-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require("./includes.js");
fluid.registerNamespace("gpii.tests.handlebars.client.templateFormControl");

fluid.defaults("gpii.tests.handlebars.browser.templateFormControl.caseHolder", {
gradeNames: ["gpii.test.webdriver.caseHolder"],
gradeNames: ["gpii.test.handlebars.browser.caseHolder.base"],
rawModules: [{
name: "Testing the `templateFormControl` client-side grade...",
tests: [
Expand Down
2 changes: 1 addition & 1 deletion tests/js/browser/includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ var gpii = fluid.registerNamespace("gpii");
fluid.require("%gpii-webdriver");
gpii.webdriver.loadTestingSupport();

fluid.require("%gpii-handlebars");
require("../../../");
require("./lib/fixtures");
require("./lib/helpers");
44 changes: 43 additions & 1 deletion tests/js/browser/lib/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,50 @@
/* eslint-env node */
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");

var path = require("path");

require("gpii-express");
gpii.express.loadTestingSupport();

require("../../test-harness");
require("./helpers");

fluid.registerNamespace("gpii.test.handlebars.browser.caseHolder");

gpii.test.handlebars.browser.caseHolder.saveCoverageData = function (that, coverageData) {
var filename = "coverage-webdriver-" + Date.now() + "-" + that.id + ".json";

var realBasePath = path.resolve(fluid.module.resolvePath("%gpii-handlebars"), "..");
var crudelyResolvedPath = fluid.stringTemplate(that.options.coverageDir, { "gpii-handlebars": realBasePath });

gpii.test.handlebars.browser.saveCoverageData(crudelyResolvedPath, filename, coverageData);
};

/*
A caseholder to take care of optionally collecting coverage data at the end of each run.
*/
fluid.defaults("gpii.test.handlebars.browser.caseHolder.base", {
gradeNames: ["gpii.test.webdriver.caseHolder.base"],
coverageDir: "%gpii-handlebars/coverage",
sequenceStart: gpii.test.express.standardSequenceStart,
sequenceEnd: [
{
func: "{gpii.test.handlebars.browser.environment}.webdriver.executeScript",
args: [gpii.test.handlebars.browser.getCoverageData]
},
{
event: "{gpii.test.handlebars.browser.environment}.webdriver.events.onExecuteScriptComplete",
listener: "gpii.test.handlebars.browser.caseHolder.saveCoverageData",
args: ["{that}", "{arguments}.0"]
},
{ func: "{gpii.test.handlebars.browser.environment}.events.stopFixtures.fire", args: [] },
{ listener: "fluid.identity", event: "{testEnvironment}.events.onFixturesStopped"}
]
});

/*
Expand All @@ -30,7 +72,7 @@ require("../../test-harness");
*/
fluid.defaults("gpii.test.handlebars.browser.caseHolder", {
gradeNames: ["gpii.test.webdriver.caseHolder"],
gradeNames: ["gpii.test.handlebars.browser.caseHolder.base"],
matchDefs: {
standard: {
markdown: {
Expand Down
14 changes: 14 additions & 0 deletions tests/js/browser/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ fluid.registerNamespace("gpii.test.handlebars.browser");

var jqUnit = require("node-jqunit");

var fs = require("fs");
var path = require("path");

require("../../../../");

/* globals $ */

gpii.test.handlebars.browser.equalThingsAreTrue = function (path, fnName) {
Expand Down Expand Up @@ -38,6 +43,15 @@ gpii.test.handlebars.browser.getJSONContent = function (path) {
return JSON.parse($(path).html());
};

gpii.test.handlebars.browser.getCoverageData = function () {
return JSON.stringify(window.__coverage__ || {}, null, 2);
};

gpii.test.handlebars.browser.saveCoverageData = function (coveragePath, filename, data) {
var outputPath = path.resolve(coveragePath, filename);
fs.writeFileSync(outputPath, data);
};

/**
*
* Test a single WebElement to see if it matches a pattern.
Expand Down
51 changes: 51 additions & 0 deletions tests/js/lib/instrument-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Instrument our source including config files and templates for use in preparing browser coverage reports
with gpii-webdriver/.
*/
/* eslint-env node */
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");

require("gpii-testem");
require("../../../");

fluid.registerNamespace("gpii.tests.handlebars.instrumentation");

gpii.tests.handlebars.instrumentation.options = {
sources: ["./src/**/*.js", "./index.js"],
excludes: [],
nonSources: [
"./tests/**",
"./Gruntfile.js",
"./node_modules/gpii-binder/src/js/binder.js",
"./node_modules/handlebars/dist/handlebars.js",
"./node_modules/infusion/dist/infusion-all.js",
"./node_modules/infusion/src/framework/core/js/DataBinding.js",
"./node_modules/infusion/src/framework/core/js/Fluid.js",
"./node_modules/infusion/src/framework/core/js/FluidDOMUtilities.js",
"./node_modules/infusion/src/framework/core/js/FluidDocument.js",
"./node_modules/infusion/src/framework/core/js/FluidIoC.js",
"./node_modules/infusion/src/framework/core/js/FluidRequests.js",
"./node_modules/infusion/src/framework/core/js/FluidView.js",
"./node_modules/infusion/src/framework/core/js/MessageResolver.js",
"./node_modules/infusion/src/framework/core/js/ModelTransformation.js",
"./node_modules/infusion/src/framework/core/js/ModelTransformationTransforms.js",
"./node_modules/infusion/src/framework/renderer/js/fluidParser.js",
"./node_modules/infusion/src/framework/renderer/js/fluidRenderer.js",
"./node_modules/infusion/src/lib/fastXmlPull/js/fastXmlPull.js",
"./node_modules/infusion/src/lib/jquery/core/js/jquery.js",
"./node_modules/markdown-it/dist/markdown-it.js",
"./node_modules/gpii-binder/src/js/binder.js",
"./node_modules/handlebars/dist/handlebars.js",
"./node_modules/markdown-it/dist/markdown-it.js"
],
istanbulOptions: {
produceSourceMap: true,
autoWrap: true
}
};

gpii.testem.instrumenter.instrument("%gpii-handlebars", "%gpii-handlebars/instrumented", gpii.tests.handlebars.instrumentation.options);
1 change: 0 additions & 1 deletion tests/js/server/all-server-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require("./errorRenderingMiddleware-tests");
require("./first-matching-path-tests");
require("./i18n-unit-tests");
require("./inline-tests");
// TODO: These don't work!
require("./inlineMessageBundlingMiddleware-tests");
require("./live-reload-tests");
require("./resolver-tests");
Expand Down
2 changes: 1 addition & 1 deletion tests/js/server/watcher-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jqUnit.asyncTest("Large writes should be complete before we are notified of a fi
jqUnit.assertEquals("The path should be correct...", templatePath, path);
var fileContent = fs.readFileSync(templatePath, "utf8");
jqUnit.assertEquals("The file's contents should be correct...", templateContent, fileContent);
fs.unlink(templatePath);
fs.unlinkSync(templatePath);
watcherComponent.destroy();
});

Expand Down
Loading

0 comments on commit e5c4e42

Please sign in to comment.