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

chore: migrate from nodeunit to jest #640

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e5f3528
chore: migrate from nodeunit to Jest
cesine Nov 26, 2024
a231955
test: migrate Legend and Scatterplot renderer tests to Jest
cesine Nov 26, 2024
ed1805a
test: Improve HoverDetail test coverage
cesine Nov 26, 2024
17d7596
chore: Update Jest config for accurate coverage reporting
cesine Nov 26, 2024
a163d0e
baseline coverage
cesine Nov 26, 2024
227ac0c
test: Migrate Rickshaw.Graph.Axis.Y test to Jest
cesine Nov 26, 2024
7379291
test: Migrate Rickshaw.Graph.Axis.X test to Jest
cesine Nov 26, 2024
85413f7
test: Migrate Rickshaw.Graph.Annotate test to Jest
cesine Nov 26, 2024
38bff07
test: Migrate Rickshaw.Fixtures.Time test to Jest
cesine Nov 26, 2024
83c98b8
test: Migrate Rickshaw.Fixtures.Time.Local test to Jest
cesine Nov 26, 2024
83e96a3
before asking to refactor global state in beforeEach
cesine Nov 26, 2024
d4231ed
test: Migrate Rickshaw.Graph.RangeSlider test to Jest
cesine Nov 26, 2024
7970a6b
test: Migrate Rickshaw.Graph.RangeSlider test to Jest
cesine Nov 26, 2024
c390782
test: Migrate Rickshaw.Graph.DragZoom test to Jest
cesine Nov 26, 2024
06e71fe
test: Migrate Rickshaw.Graph.Renderer.Multi test to Jest
cesine Nov 26, 2024
2a85df1
test: Migrate Rickshaw.Series.FixedDuration test to Jest
cesine Nov 26, 2024
04f50b9
test: migrate Rickshaw.Graph tests to Jest
cesine Nov 26, 2024
ba9b4e3
test: migrate Rickshaw.Color.Palette tests to Jest
cesine Nov 26, 2024
863b07c
test: migrate Rickshaw.Graph.RangeSlider.Preview tests to Jest
cesine Nov 26, 2024
d6e1078
test: Migrate Graph Renderer tests to Jest
cesine Nov 26, 2024
dce3641
test: Migrate Rickshaw core tests to Jest
cesine Nov 26, 2024
e70c472
test: Improve Rickshaw.Series fill methods test
cesine Nov 26, 2024
f1deeb5
remove coverage baseline
cesine Nov 26, 2024
39ffe72
Merge branch 'main' into coverage
cesine Nov 26, 2024
e75a413
jest uses null coalescing which is not available in node 12
cesine Nov 26, 2024
90424a1
add coverage expecations
cesine Nov 26, 2024
e16c721
chore: update jest coverage thresholds
cesine Nov 26, 2024
bb01012
more generated test cases
cesine Nov 27, 2024
baa626b
remove sinon
cesine Nov 27, 2024
6a5a1f4
test: improve Highlight behavior test coverage
cesine Nov 27, 2024
4f0d2fc
test: Add test suite for Rickshaw.Graph.Behavior.Series.Order
cesine Nov 27, 2024
f241019
test: Add test suite for Rickshaw.Graph.Renderer.LinePlot
cesine Nov 27, 2024
7ecedb2
update coverage expectations
cesine Nov 27, 2024
116a6a9
only report to coveralls on main
cesine Nov 27, 2024
c57e5ef
clean up jsdom
cesine Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 22.x]
node-version: [22.x]
Copy link
Member Author

Choose a reason for hiding this comment

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

jest no longer supports node 12 https://jestjs.io/docs/upgrading-to-jest29

https://github.com/cesine/rickshaw/actions/runs/12040292801/job/33569879332

Run npm run coverage

> [email protected] coverage /home/runner/work/rickshaw/rickshaw
> jest --coverage

/home/runner/work/rickshaw/rickshaw/node_modules/jest/node_modules/jest-cli/build/run.js:135
    if (error?.stack) {
              ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:[9](https://github.com/cesine/rickshaw/actions/runs/12040317722/job/33569956048#step:6:10)15:16)


env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
Expand All @@ -39,10 +39,7 @@ jobs:

- name: Run tests
run: npm run coverage

- name: Run Coveralls
run: npm run coveralls


- name: Check for changed dist files
run: |
git fetch origin main --depth=1
Expand All @@ -53,4 +50,8 @@ jobs:
echo -e "\033[31mChanged files:"
echo "$DIST_CHANGED"
exit 1
fi
fi

- name: Run Coveralls
run: npm run coveralls
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ CSS_MIN=$(NODE_MODULES)/.bin/cleancss
JS_MIN=$(NODE_MODULES)/.bin/uglifyjs
JS_HINT=$(NODE_MODULES)/.bin/jshint
D3=$(NODE_MODULES)/d3
JSDOM=$(NODE_MODULES)/jsdom
NODEUNIT=$(NODE_MODULES)/nodeunit

CSS_FILES=\
src/css/detail.css\
Expand Down Expand Up @@ -61,7 +59,7 @@ build: rickshaw.min.css rickshaw.min.js
clean:
rm -rf rickshaw.css rickshaw.js rickshaw.min.*

test: $(D3) $(JSDOM) $(NODEUNIT)
test: $(D3)
npm test

$(JS_HINT):
Expand All @@ -76,12 +74,6 @@ $(JS_MIN):
$(D3):
npm install d3

$(JSDOM):
npm install jsdom

$(NODEUNIT):
npm install nodeunit

rickshaw.css: $(CSS_FILES)
cat $(CSS_FILES) > rickshaw.css

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Rickshaw relies on the fantastic [D3 visualization library](http://mbostock.gith

Some extensions require [jQuery](http://jquery.com) and [jQuery UI](http://jqueryui.com), but for drawing some basic graphs you'll be okay without.

Rickshaw uses [jsdom](https://github.com/tmpvar/jsdom) to run unit tests in Node to be able to do SVG manipulation. As of the jsdom 7.0.0 release, jsdom requires Node.js 4 or newer [jsdom changelog](https://github.com/tmpvar/jsdom/blob/master/Changelog.md#700). If you want to run the tests on your machine, and you don't have access to a version of node >= 4.0, you can `npm install jsdom@3` so that you can run the tests using the [3.x branch of jsdom](https://github.com/tmpvar/jsdom/tree/3.x).

## Rickshaw.Graph

Expand Down
24 changes: 24 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
testEnvironment: 'jsdom',
moduleDirectories: ['node_modules'],
testMatch: ['**/**/*.test.js'],
collectCoverageFrom: [
'Rickshaw.*.js',
'rickshaw.js',
'!rickshaw.min.js',
'!**/node_modules/**',
],
coverageThreshold: {
global: {
branches: 59,
functions: 62,
lines: 67,
statements: 66,
}
},
setupFiles: ['./jest.setup.js'],
transform: {},
testEnvironmentOptions: {
url: 'http://localhost/'
}
};
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Set up any global variables needed for testing
global.d3 = require('d3');

// No need to extend expect here as we're not using custom matchers yet
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
"clean-css-cli": "^4.3.0",
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jquery": "^3.2.1",
"jsdom": "^8.1.0",
"jshint": "^2.9.5",
"nodemon": "^1.11.0",
"nodeunit": "^0.9.1",
"sinon": "^2.3.8",
"uglify-js": "^2.8.29"
},
"scripts": {
"build": "make clean && make",
"examples": "open examples/index.html",
"lint": "jshint src/js/*",
"test": "make && nodeunit tests",
"test": "jest",
"test:watch": "jest --watch",
"watch": "nodemon --watch src --exec make rickshaw.js",
"coverage": "istanbul cover nodeunit tests --reporter=lcov",
"coverage": "jest --coverage",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"preversion:src": "sed \"s/version: '[^,]*'/version: '$npm_package_version'/\" src/js/Rickshaw.js > output && mv output src/js/Rickshaw.js",
"preversion:bower": "sed 's/\"version\": \"[^,]*\"/\"version\": \"'$npm_package_version'\"/' bower.json > output && mv output bower.json",
Expand Down
109 changes: 57 additions & 52 deletions tests/Rickshaw.Class.test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,57 @@
var Rickshaw = require('../rickshaw');

exports.load = function(test) {

test.equal(typeof Rickshaw.Class, 'object', 'Rickshaw.Class is a function');
test.done();
};

exports.instantiation = function(test) {

Rickshaw.namespace('Rickshaw.Sample.Class');

Rickshaw.Sample.Class = Rickshaw.Class.create({
name: 'sample',
concat: function(suffix) {
return [this.name, suffix].join(' ');
}
});

var sample = new Rickshaw.Sample.Class();
test.equal(sample.concat('polka'), 'sample polka');

Rickshaw.namespace('Rickshaw.Sample.Class.Prefix');

Rickshaw.Sample.Subclass = Rickshaw.Class.create( Rickshaw.Sample.Class, {
name: 'sampler'
});

var sampler = new Rickshaw.Sample.Subclass();
test.equal(sampler.concat('polka'), 'sampler polka');

test.done();
};

exports.array = function(test) {

Rickshaw.namespace('Rickshaw.Sample.Array');

Rickshaw.Sample.Array = Rickshaw.Class.create(Array, {
second: function() {
return this[1];
}
});

var array = new Rickshaw.Sample.Array();
array.push('red');
array.push('blue');

test.equal(array.second(), 'blue');

test.done();
};
const Rickshaw = require('../rickshaw');

describe('Rickshaw.Class', () => {
test('should be defined as an object', () => {
expect(typeof Rickshaw.Class).toBe('object');
});

describe('instantiation', () => {
test('should create a basic class instance', () => {
// Create fresh class definition for this test
const TestClass = Rickshaw.Class.create({
name: 'sample',
concat: function(suffix) {
return [this.name, suffix].join(' ');
}
});

const sample = new TestClass();
expect(sample.concat('polka')).toBe('sample polka');
});

test('should create a subclass instance', () => {
// Create fresh parent class for this test
const ParentClass = Rickshaw.Class.create({
name: 'sample',
concat: function(suffix) {
return [this.name, suffix].join(' ');
}
});

// Create fresh subclass for this test
const SubClass = Rickshaw.Class.create(ParentClass, {
name: 'sampler'
});

const sampler = new SubClass();
expect(sampler.concat('polka')).toBe('sampler polka');
});
});

describe('array inheritance', () => {
test('should extend Array functionality', () => {
// Create fresh array class for this test
const TestArray = Rickshaw.Class.create(Array, {
second: function() {
return this[1];
}
});

const array = new TestArray();
array.push('red');
array.push('blue');

expect(array.second()).toBe('blue');
});
});
});
Loading