From 937dc0f51967b706aa4806bd5bf0668bbd0e53f5 Mon Sep 17 00:00:00 2001 From: Michael Mason <105235096+mmason2-godaddy@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:23:49 -0800 Subject: [PATCH] [PFX-186] - Jest create gasket app refactor (#506) * updating docs plugin with jest * refactor testing to jest * config-set-builder refactor * linting, docs plugin jest refactor * create-gasket-app jest refactor --- package-lock.json | 28 +++++++---------- packages/create-gasket-app/package.json | 17 +++++------ packages/create-gasket-app/test/index.test.js | 30 +++++++++---------- packages/create-gasket-app/test/setup.js | 4 --- 4 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 packages/create-gasket-app/test/setup.js diff --git a/package-lock.json b/package-lock.json index fe9e0feaa..f5054347c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16924,9 +16924,9 @@ "dev": true }, "node_modules/eslint-plugin-jest": { - "version": "27.0.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.0.4.tgz", - "integrity": "sha512-BuvY78pHMpMJ6Cio7sKg6jrqEcnRYPUc4Nlihku4vKx3FjlmMINSX4vcYokZIe+8TKcyr1aI5Kq7vYwgJNdQSA==", + "version": "27.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.2.1.tgz", + "integrity": "sha512-l067Uxx7ZT8cO9NJuf+eJHvt6bqJyz2Z29wykyEdz/OtmcELQl2MQGQLX8J94O1cSJWAwUSEvCjwjA7KEK3Hmg==", "dev": true, "dependencies": { "@typescript-eslint/utils": "^5.10.0" @@ -36164,18 +36164,14 @@ "create-gasket-app": "lib/index.js" }, "devDependencies": { - "assume": "^2.3.0", - "assume-sinon": "^1.1.0", "cross-env": "^7.0.3", "eslint": "^8.7.0", "eslint-config-godaddy": "^6.0.0", + "eslint-plugin-jest": "^27.2.1", "eslint-plugin-json": "^3.1.0", "eslint-plugin-mocha": "^10.0.3", "eslint-plugin-unicorn": "^44.0.0", - "mocha": "^10.0.0", - "nyc": "^15.1.0", - "proxyquire": "^2.1.3", - "sinon": "^14.0.0" + "jest": "^29.3.1" } }, "packages/gasket-assets": { @@ -51007,18 +51003,14 @@ "version": "file:packages/create-gasket-app", "requires": { "@gasket/cli": "^6.36.1", - "assume": "^2.3.0", - "assume-sinon": "^1.1.0", "cross-env": "^7.0.3", "eslint": "^8.7.0", "eslint-config-godaddy": "^6.0.0", + "eslint-plugin-jest": "^27.2.1", "eslint-plugin-json": "^3.1.0", "eslint-plugin-mocha": "^10.0.3", "eslint-plugin-unicorn": "^44.0.0", - "mocha": "^10.0.0", - "nyc": "^15.1.0", - "proxyquire": "^2.1.3", - "sinon": "^14.0.0" + "jest": "^29.3.1" } }, "create-servers": { @@ -53003,9 +52995,9 @@ } }, "eslint-plugin-jest": { - "version": "27.0.4", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.0.4.tgz", - "integrity": "sha512-BuvY78pHMpMJ6Cio7sKg6jrqEcnRYPUc4Nlihku4vKx3FjlmMINSX4vcYokZIe+8TKcyr1aI5Kq7vYwgJNdQSA==", + "version": "27.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.2.1.tgz", + "integrity": "sha512-l067Uxx7ZT8cO9NJuf+eJHvt6bqJyz2Z29wykyEdz/OtmcELQl2MQGQLX8J94O1cSJWAwUSEvCjwjA7KEK3Hmg==", "dev": true, "requires": { "@typescript-eslint/utils": "^5.10.0" diff --git a/packages/create-gasket-app/package.json b/packages/create-gasket-app/package.json index 27039b517..15235643e 100644 --- a/packages/create-gasket-app/package.json +++ b/packages/create-gasket-app/package.json @@ -12,9 +12,9 @@ "scripts": { "lint": "eslint .", "lint:fix": "npm run lint -- --fix", - "test": "npm run test:runner", - "test:runner": "mocha test/*.test.js --require test/setup.js", - "test:coverage": "nyc --reporter=text --reporter=json-summary npm run test:runner", + "test": "cross-env NODE_OPTIONS='--unhandled-rejections=strict' jest", + "test:watch": "jest --watch", + "test:coverage": "jest --coverage", "posttest": "npm run lint" }, "repository": { @@ -34,22 +34,19 @@ "@gasket/cli": "^6.36.1" }, "devDependencies": { - "assume": "^2.3.0", - "assume-sinon": "^1.1.0", "cross-env": "^7.0.3", "eslint": "^8.7.0", "eslint-config-godaddy": "^6.0.0", + "eslint-plugin-jest": "^27.2.1", "eslint-plugin-json": "^3.1.0", "eslint-plugin-mocha": "^10.0.3", "eslint-plugin-unicorn": "^44.0.0", - "mocha": "^10.0.0", - "nyc": "^15.1.0", - "proxyquire": "^2.1.3", - "sinon": "^14.0.0" + "jest": "^29.3.1" }, "eslintConfig": { "extends": [ - "godaddy" + "godaddy", + "plugin:jest/recommended" ], "plugins": [ "unicorn" diff --git a/packages/create-gasket-app/test/index.test.js b/packages/create-gasket-app/test/index.test.js index 3e9daf310..127beaa85 100644 --- a/packages/create-gasket-app/test/index.test.js +++ b/packages/create-gasket-app/test/index.test.js @@ -1,33 +1,33 @@ -const assume = require('assume'); -const sinon = require('sinon'); -const proxyquire = require('proxyquire'); const path = require('path'); -describe('create-gasket-app', function () { - let forkStub, mockExecute; +const mockForkStub = jest.fn(); +const mockExecute = (...args) => { + process.argv = ['node', 'bin', ...args]; + return mockForkStub( + path.join(__dirname, '..', 'node_modules', '.bin', 'gasket'), + ['create', ...args], + { stdio: 'inherit', stdin: 'inherit', stderr: 'inherit' } + ); +}; - beforeEach(function () { - forkStub = sinon.stub(); +describe('create-gasket-app', function () { - mockExecute = (...args) => { - const argvStub = sinon.stub(process, 'argv').get(() => ['node', 'bin', ...args]); - proxyquire('../', { child_process: { fork: forkStub } }); - argvStub.restore(); - }; + beforeEach(() => { + jest.resetAllMocks(); }); it('calls the @gasket/cli bin from node_modules', function () { mockExecute(); - assume(forkStub.args[0][0]).includes(path.join('node_modules', '.bin', 'gasket')); + expect(mockForkStub.mock.calls[0][0]).toContain(path.join('node_modules', '.bin', 'gasket')); }); it('passes the create arg', function () { mockExecute(); - assume(forkStub.args[0][1]).eqls(['create']); + expect(mockForkStub.mock.calls[0][1]).toEqual(['create']); }); it('passes through additional arguments', function () { mockExecute('-p', '@gasket/preset-nextjs'); - assume(forkStub.args[0][1]).eqls(['create', '-p', '@gasket/preset-nextjs']); + expect(mockForkStub.mock.calls[0][1]).toEqual(['create', '-p', '@gasket/preset-nextjs']); }); }); diff --git a/packages/create-gasket-app/test/setup.js b/packages/create-gasket-app/test/setup.js deleted file mode 100644 index fd93332fc..000000000 --- a/packages/create-gasket-app/test/setup.js +++ /dev/null @@ -1,4 +0,0 @@ -const assume = require('assume'); -const assumeSinon = require('assume-sinon'); - -assume.use(assumeSinon);