Skip to content

Commit

Permalink
[PFX-186] - Jest create gasket app refactor (#506)
Browse files Browse the repository at this point in the history
* updating docs plugin with jest

* refactor testing to jest

* config-set-builder refactor

* linting, docs plugin jest refactor

* create-gasket-app jest refactor
  • Loading branch information
mmason2-godaddy authored Jan 10, 2023
1 parent 427f73a commit 937dc0f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 47 deletions.
28 changes: 10 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions packages/create-gasket-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions packages/create-gasket-app/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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']);
});
});
4 changes: 0 additions & 4 deletions packages/create-gasket-app/test/setup.js

This file was deleted.

0 comments on commit 937dc0f

Please sign in to comment.