-
-
Notifications
You must be signed in to change notification settings - Fork 9
test: add test for cli #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0f06335
test: initial test for interative mode
bjohansebas b185778
ci: build on windows and macos
bjohansebas d97d5f3
Improve name test
bjohansebas 724347a
deps: remove execa
bjohansebas 9769424
Add build directory to tsconfig
kjugi 7dd69a9
update options param types and add console.info for exit reason
kjugi 7347e37
delete build from unit test CI
kjugi 64fd08a
update transform unit test with mocks
kjugi 68b2a43
revert change in ci.yml file for github workflow
kjugi bdb8490
prevent redundant return from transform method and adjust index file
kjugi 681df8f
update gitignore
kjugi df20140
update transform list config
kjugi 7ec60f2
update tsconfig and exclude all tests files
kjugi a01ef4a
exclude build dir
bjohansebas 200cf3c
update jest config file to ignore build directory
kjugi cb3ef65
Merge remote-tracking branch 'origin/add-test-cli' into add-test-cli
kjugi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ node_modules | |
| coverage | ||
|
|
||
| # Build Outputs | ||
| dist | ||
| build | ||
|
|
||
| # Debug | ||
| npm-debug.log* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { join } from 'node:path' | ||
| import { run } from 'jscodeshift/src/Runner' | ||
| import prompts from 'prompts' | ||
| import { transform } from '../transform' | ||
|
|
||
| jest.mock('jscodeshift/src/Runner', () => ({ | ||
| run: jest.fn(), | ||
| })) | ||
|
|
||
| describe('interactive mode', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('runs without codemodName and source params provided', async () => { | ||
| const spyOnConsole = jest.spyOn(console, 'log').mockImplementation() | ||
|
|
||
| prompts.inject(['magic-redirect']) | ||
| prompts.inject(['./transforms/__testfixtures__']) | ||
|
|
||
| await transform(undefined, undefined, { dry: true, silent: true }) | ||
|
|
||
| expect(spyOnConsole).not.toHaveBeenCalled() | ||
| expect(run).toHaveBeenCalledTimes(1) | ||
| expect(run).toHaveBeenCalledWith( | ||
| join(__dirname, '../../', 'transforms/magic-redirect.js'), | ||
| ['./transforms/__testfixtures__'], | ||
| { | ||
| babel: false, | ||
| dry: true, | ||
| extensions: 'cts,mts,ts,js,mjs,cjs', | ||
| ignorePattern: '**/node_modules/**', | ||
| silent: true, | ||
| verbose: 0, | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| it('runs properly on incorrect user input', async () => { | ||
| const spyOnConsole = jest.spyOn(console, 'log').mockImplementation() | ||
|
|
||
| prompts.inject(['magic-redirect']) | ||
|
|
||
| await transform('bad-codemod', './transforms/__testfixtures__', { | ||
| dry: true, | ||
| silent: true, | ||
| }) | ||
|
|
||
| expect(spyOnConsole).not.toHaveBeenCalled() | ||
| expect(run).toHaveBeenCalledTimes(1) | ||
| expect(run).toHaveBeenCalledWith( | ||
| join(__dirname, '../../', 'transforms/magic-redirect.js'), | ||
| ['./transforms/__testfixtures__'], | ||
| { | ||
| babel: false, | ||
| dry: true, | ||
| extensions: 'cts,mts,ts,js,mjs,cjs', | ||
| ignorePattern: '**/node_modules/**', | ||
| silent: true, | ||
| verbose: 0, | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| it('runs with codemodName and without source param provided', async () => { | ||
| const spyOnConsole = jest.spyOn(console, 'log').mockImplementation() | ||
|
|
||
| prompts.inject(['__testfixtures__']) | ||
|
|
||
| await transform('magic-redirect', undefined, { | ||
| dry: true, | ||
| silent: true, | ||
| }) | ||
|
|
||
| expect(spyOnConsole).not.toHaveBeenCalled() | ||
| expect(run).toHaveBeenCalledTimes(1) | ||
| expect(run).toHaveBeenCalledWith(join(__dirname, '../../', 'transforms/magic-redirect.js'), ['__testfixtures__'], { | ||
| babel: false, | ||
| dry: true, | ||
| extensions: 'cts,mts,ts,js,mjs,cjs', | ||
| ignorePattern: '**/node_modules/**', | ||
| silent: true, | ||
| verbose: 0, | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('Non-Interactive Mode', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('Transforms code with codemodName and source params provided', async () => { | ||
| const spyOnConsole = jest.spyOn(console, 'log').mockImplementation() | ||
|
|
||
| await transform('magic-redirect', '__testfixtures__', { | ||
| dry: true, | ||
| silent: true, | ||
| }) | ||
|
|
||
| expect(spyOnConsole).not.toHaveBeenCalled() | ||
| expect(run).toHaveBeenCalledTimes(1) | ||
| expect(run).toHaveBeenCalledWith(join(__dirname, '../../', 'transforms/magic-redirect.js'), ['__testfixtures__'], { | ||
| babel: false, | ||
| dry: true, | ||
| extensions: 'cts,mts,ts,js,mjs,cjs', | ||
| ignorePattern: '**/node_modules/**', | ||
| silent: true, | ||
| verbose: 0, | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,11 @@ | |
| "private": true, | ||
| "version": "0.0.1", | ||
| "description": "Codemods for updating express servers.", | ||
| "main": "index.js", | ||
| "main": "build/index.js", | ||
| "contributors": ["Sebastian Beltran <[email protected]>", "Filip Kudla <[email protected]>"], | ||
| "license": "MIT", | ||
| "bin": "./index.js", | ||
| "files": ["transforms/*.js", "commands/*.js", "utils/*.js", "config.js", "index.js"], | ||
| "bin": "build/index.js", | ||
| "files": ["build/transforms/*.js", "build/commands/*.js", "build/utils/*.js", "build/config.js", "build/index.js"], | ||
| "scripts": { | ||
| "dev": "tsc -d -w -p tsconfig.json", | ||
| "build": "tsc -d -p tsconfig.json", | ||
|
|
@@ -18,7 +18,6 @@ | |
| }, | ||
| "dependencies": { | ||
| "commander": "^12.1.0", | ||
| "execa": "^5.1.1", | ||
| "fast-glob": "^3.3.2", | ||
| "jscodeshift": "^17.1.1", | ||
| "picocolors": "^1.1.1", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.