Skip to content

Commit

Permalink
Merge pull request #195 from Mr0grog/191-work-in-modern-nodejs
Browse files Browse the repository at this point in the history
Get tests and builds working in current Node.js versions
  • Loading branch information
pimterry committed Jan 25, 2024
2 parents 4175824 + 03cffed commit f7becd9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 55 deletions.
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
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

0 comments on commit f7becd9

Please sign in to comment.