Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get tests and builds working in current Node.js versions #195

Merged
merged 11 commits into from
Jan 25, 2024
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ indent_size = 2

[*.{yaml,yml}]
indent_size = 2

[vendor/grunt-template-jasmine-requirejs/**/*]
indent_size = 2
Comment on lines +26 to +27
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably should have done this when I vendored grunt-template-jasmine-requirejs. It was helpful when I had to make changes. 🤷

12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 10
node-version: 20
cache: npm
cache-dependency-path: 'package.json'

Expand All @@ -37,7 +37,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 10
node-version: 20
cache: npm
cache-dependency-path: 'package.json'

Expand All @@ -51,9 +51,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# Ideally we'd also test on [12, 14, 16, 18, 20], but the current
# tooling does not support them.
node_version: [6, 8, 10]
node_version: [8, 10, 12, 14, 16, 18, 20]

steps:
- uses: actions/checkout@v4
Expand All @@ -80,7 +78,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 8
node-version: 20
cache: npm
cache-dependency-path: 'package.json'

Expand All @@ -99,7 +97,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 10
node-version: 20
cache: npm
cache-dependency-path: 'package.json'

Expand Down
62 changes: 22 additions & 40 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var Jasmine = require('jasmine');

module.exports = function (grunt) {
var jasmineRequireJsOptions = {
specs: 'test/*-test.js',
Expand Down Expand Up @@ -54,45 +56,11 @@ module.exports = function (grunt) {
options: {
specs: 'test/global-integration-with-new-context.js',
}
},
// Wraps the `requirejs` configuration above with Instanbul code
// coverage tracking.
withCoverage: {
src: 'lib/**/*.js',
options: {
specs: jasmineRequireJsOptions.specs,
helpers: jasmineRequireJsOptions.helpers,
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
coverage: 'coverage/coverage.json',
report: [
{
type: 'html',
options: {
dir: 'coverage'
}
},
{
type: 'lcov',
options: {
dir: 'coverage'
}
}
],

template: require('./vendor/grunt-template-jasmine-requirejs')
}
}
}
},
"jasmine_node": {
test: {
options: {
match: "node-integration.",
matchall: true,
projectRoot: "./test",
useHelpers: false
}
jasmine_node: {
options: {
specs: ['test/node-integration.js']
}
},
open: {
Expand Down Expand Up @@ -155,7 +123,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');

Expand All @@ -164,19 +131,34 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-contrib-clean');

// Run Jasmine with Node.js tests (as opposed to browser tests).
//
// NOTE: This is designed for Jasmine 2.4, which matches the version used
// in `grunt-contrib-jasmine`. If that package is updated, this should also
// be updated to match.
grunt.registerTask('jasmine_node', 'Run Jasmine in Node.js', function() {
var done = this.async();

var jasmine = new Jasmine({ projectBaseDir: __dirname });
jasmine.onComplete(function(success) {
done(success);
});

jasmine.execute(this.options().specs);
});

// Build a distributable release
grunt.registerTask('dist', ['test', 'dist-build']);
grunt.registerTask('dist-build', ['concat', 'uglify']);

// Check everything is good
grunt.registerTask('test', ['jshint', 'test-browser', 'test-node']);
grunt.registerTask('test-browser', ['jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine:withCoverage']);
grunt.registerTask('test-browser', ['jasmine:global', 'preprocess', 'jasmine:context', 'clean:test', 'jasmine:requirejs']);
grunt.registerTask('test-node', ['jasmine_node']);

// Test with a live server and an actual browser
grunt.registerTask('integration-test', ['jasmine:requirejs:src:build', 'open:jasmine', 'connect:test:keepalive']);

// Default task.
grunt.registerTask('default', 'test');

};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jasmine": "~1.0.3",
"grunt-contrib-jasmine": "^4.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.4.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-jasmine-node": "~0.2.1",
"grunt-open": "~0.2.3",
"grunt-preprocess": "^5.1.0",
"grunt-template-jasmine-istanbul": "~0.4.0",
"jasmine": "^2.4.1",
"typescript": "^3.5.1"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ define(function () {
};

self.isCookieStorageAvailable = function isCookieStorageAvailable() {
if (window && window.document && window.document.cookie) {
if (window && window.document && window.document.cookie != null) {
// We need to check not just that the cookie objects are available, but that they work, because
// if we run from file:// URLs they appear present but are non-functional
window.document.cookie = "test=hi;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function resolvePath(filepath) {
return path.resolve(filepath);
}

function moveRequireJs(grunt, task, versionOrPath) {
// LOGLEVEL-FORK: copying tempfiles now requires info from the `context` object.
function moveRequireJs(grunt, task, context, versionOrPath) {
var pathToRequireJS,
versionReg = /^(\d\.?)*$/;

Expand All @@ -74,8 +75,10 @@ function moveRequireJs(grunt, task, versionOrPath) {
throw new Error('local file path of requirejs [' + versionOrPath + '] was not found');
}
}
task.copyTempFile(pathToRequireJS,'require.js');
task.copyTempFile(pathToRequireJS, path.join(context.temp, 'require.js'));
}
// END LOGLEVEL-FORK


exports.process = function(grunt, task, context) {

Expand Down Expand Up @@ -149,7 +152,9 @@ exports.process = function(grunt, task, context) {
});
}

moveRequireJs(grunt, task, version);
// LOGLEVEL-FORK: this function now requires context info
moveRequireJs(grunt, task, context, version);
// END LOGLEVEL-FORK

context.serializeRequireConfig = function(requireConfig) {
var funcCounter = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
<script src="<%= temp ? temp + "/" : temp %>require.js"></script>

<% with (scripts) { %>
<% [].concat(jasmine, boot, helpers).forEach(function(script){ %>
<% /* LOGLEVEL-FORK: Include new script types used by grunt-contrib-jasmine v4 */ %>
<% [].concat(polyfills, jasmine, boot, boot2, helpers).forEach(function(script){ %>
<script src="<%= script %>"></script>
<% }) %>
<% /* END LOGLEVEL-FORK */ %>
<% }; %>

<script>
Expand Down