Skip to content

Commit 6cf732b

Browse files
[PFX-186] - jest refactor @gasket/plugin-nextjs (#535)
1 parent 82acf6d commit 6cf732b

File tree

9 files changed

+291
-324
lines changed

9 files changed

+291
-324
lines changed

package-lock.json

Lines changed: 8 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/gasket-plugin-nextjs/package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
"scripts": {
1313
"lint": "eslint .",
1414
"lint:fix": "npm run lint -- --fix",
15-
"test": "npm run test:runner",
16-
"test:runner": "mocha --require ./test/setup.js \"test/**/*.test.js\"",
17-
"test:watch": "npm run test:runner -- --watch",
18-
"test:coverage": "nyc --reporter=text --reporter=json-summary npm run test:runner",
19-
"posttest": "npm run lint",
20-
"report": "nyc report --reporter=lcov"
15+
"test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest",
16+
"test:watch": "jest --watch",
17+
"test:coverage": "jest --coverage",
18+
"posttest": "npm run lint"
2119
},
2220
"repository": {
2321
"type": "git",
@@ -51,25 +49,21 @@
5149
"@gasket/assets": "^6.36.1",
5250
"@gasket/engine": "^6.36.1",
5351
"@gasket/nextjs": "^6.37.0",
54-
"assume": "^2.3.0",
55-
"assume-sinon": "^1.1.0",
5652
"babel-eslint": "^10.1.0",
53+
"cross-env": "^7.0.3",
5754
"eslint": "^8.7.0",
5855
"eslint-config-godaddy": "^6.0.0",
5956
"eslint-config-godaddy-react": "^8.0.0",
57+
"eslint-plugin-jest": "^27.2.1",
6058
"eslint-plugin-json": "^3.1.0",
61-
"eslint-plugin-mocha": "^10.0.3",
6259
"eslint-plugin-unicorn": "^44.0.0",
60+
"jest": "^29.3.1",
6361
"lodash.merge": "^4.6.0",
64-
"mocha": "^10.0.0",
6562
"next": "^12.0.8",
6663
"next-redux-wrapper": "^8.0.0",
67-
"nyc": "^15.1.0",
6864
"prop-types": "^15.7.2",
69-
"proxyquire": "^2.1.3",
7065
"react": "^18.0.0",
71-
"react-dom": "^18.0.0",
72-
"sinon": "^14.0.0"
66+
"react-dom": "^18.0.0"
7367
},
7468
"peerDependencies": {
7569
"next": ">=10.2.0 < 13",
@@ -78,7 +72,8 @@
7872
},
7973
"eslintConfig": {
8074
"extends": [
81-
"godaddy"
75+
"godaddy",
76+
"plugin:jest/recommended"
8277
],
8378
"globals": {
8479
"expect": "readonly"
@@ -109,5 +104,8 @@
109104
"presets": [
110105
"@babel/preset-react"
111106
]
107+
},
108+
"jest": {
109+
"rootDir": "test"
112110
}
113111
}

packages/gasket-plugin-nextjs/test/apm-transaction.test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const assume = require('assume');
2-
const { spy } = require('sinon');
31
const apmTransaction = require('../lib/apm-transaction');
42

53
describe('The apmTransaction hook', () => {
@@ -8,7 +6,7 @@ describe('The apmTransaction hook', () => {
86
beforeEach(() => {
97
transaction = {
108
name: 'GET *',
11-
addLabels: spy()
9+
addLabels: jest.fn()
1210
};
1311
});
1412

@@ -18,7 +16,7 @@ describe('The apmTransaction hook', () => {
1816

1917
await apmTransaction({}, transaction, { req });
2018

21-
assume(transaction.name).equals('GET /proxy/foo');
19+
expect(transaction.name).toEqual('GET /proxy/foo');
2220
});
2321

2422
it('returns the page name if the route is for a page', async () => {
@@ -31,15 +29,15 @@ describe('The apmTransaction hook', () => {
3129

3230
await apmTransaction({}, transaction, { req });
3331

34-
assume(transaction.name).equals('/customer/[id]');
32+
expect(transaction.name).toEqual('/customer/[id]');
3533
});
3634

3735
it('does not set labels if the route is not for a page', async () => {
3836
const req = { getNextRoute: async () => null };
3937

4038
await apmTransaction({}, transaction, { req });
4139

42-
assume(transaction.addLabels).was.not.called();
40+
expect(transaction.addLabels).not.toHaveBeenCalled();
4341
});
4442

4543
it('sets dynamic route params as labels if the route is for a page', async () => {
@@ -53,6 +51,6 @@ describe('The apmTransaction hook', () => {
5351

5452
await apmTransaction({}, transaction, { req });
5553

56-
assume(transaction.addLabels).was.calledWith({ cohortId: 'Rad People' });
54+
expect(transaction.addLabels).toHaveBeenCalledWith({ cohortId: 'Rad People' });
5755
});
5856
});

0 commit comments

Comments
 (0)