-
Notifications
You must be signed in to change notification settings - Fork 4
make input paths relative to current working directory #20
Conversation
Awesome. Thanks for the contribution. 🚀 |
For relative paths you could also used 'tscodeshift -t ./dist/src/transforms/mocha.js 'my-fixture-file.ts' |
And since you updated typescript to the latest version it my be required to update the test harness as well. EDIT: Oh, don't mind. This would be located in the |
@KnisterPeter Cool, I'll remove the |
fc626b1
to
7bd544b
Compare
10edbd8
to
9734c7d
Compare
@@ -13,7 +13,7 @@ | |||
"start": "npm test -- --watch", | |||
"clean": "rimraf dist", | |||
"build": "tsc", | |||
"test": "jest", | |||
"test": "npm run build && jest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running build before jest is not required with ts-jest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, relative to how I am building stuff, this is; basically I wanted to be able to ask the compiled / for-publication version to build things at the command-line, and dist/src
doesn't exist at that point.
More comments below.
package.json
Outdated
@@ -59,13 +60,16 @@ | |||
"transform": { | |||
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" | |||
}, | |||
"testRegex": "\\.test\\.(ts|tsx)$", | |||
"testRegex": "\\.test\\.(ts|tsx|js)$", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to find js files for tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment here
src/index.test.ts
Outdated
@@ -123,3 +123,68 @@ it('convert var declarations to let declarations', () => { | |||
|
|||
expect(actual).toBe(expected); | |||
}); | |||
|
|||
test(`api`, () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you are testing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there's an else case that is very hard to get to inside of the ./transform#api.tscodeshift
function, and this test covers that else case. Sorry, I should have clarified my test case after I got it working. (Basically the coverage was lowered by me adding the files I added, so by covering the else case, I was able to get coveralls to pass.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically this: https://travis-ci.org/KnisterPeter/tscodeshift/builds/237974069#L217
relative-paths.test.js
Outdated
@@ -0,0 +1,42 @@ | |||
/* global test, expect, afterEach */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This files belongs into the src folder. Even tests are sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, in general the reason I have this .js
file is more from my lack of familiarity with TypeScript. I am more than happy to have this file be in src
, but relative to the problem I was trying to solve, I didn't wanna jump through hoops of TypeScript fixing while trying to get the gist of this thing working. I think specifically I was running into some issues trying to use path
-- this evening I'll try and regroup and clarify my intentions in this PR.
const api = { | ||
tscodeshift: (source: string|ts.Node) => { | ||
export const api = { | ||
tscodeshift: (source: string|ts.Node): Collection<any, any> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KnisterPeter I had to make this change in order to get tsc
to compile properly -- I'm guessing there's a better way to do this, but I was running into some problems locally.
relative-paths.test.js
Outdated
const execa = require('execa') | ||
const path = require('path') | ||
|
||
const CLI = path.resolve(__dirname, `./dist/src/index.js`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KnisterPeter This is the reason for that additional build step -- I want to be able to reference the compiled version of this file in the test.
src/index.test.ts
Outdated
@@ -124,7 +124,7 @@ it('convert var declarations to let declarations', () => { | |||
expect(actual).toBe(expected); | |||
}); | |||
|
|||
test(`api`, () => { | |||
test(`api.tscodeshift can process raw ts.Nodes`, () => { | |||
expect(typeof api).toBe(`object`); | |||
expect(typeof api.tscodeshift).toBe(`function`); | |||
const removeCircularCrap = (x: any): any => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this from 'Crap' to 'References' 😉
src/index.test.ts
Outdated
@@ -136,7 +136,6 @@ test(`api`, () => { | |||
return x; | |||
}; | |||
const expected = JSON.parse(JSON.stringify(removeCircularCrap(api.tscodeshift(`false`)))); | |||
// expect(JSON.parse(JSON.stringify(removeCircularCrap(expected)))).toEqual(circular) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented out lines
src/relative-paths.test.ts
Outdated
@@ -0,0 +1,50 @@ | |||
/* global test, expect, afterEach */ | |||
// https://stackoverflow.com/questions/39415661 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need this reference for the import-require statement.
Its part of the official typescript documentation. No need to quote these.
Besides all my comments. Thanks for you awesome contribution. 👍 |
I've updated your test code to do not require |
Thanks for this library, it's exactly what I was looking for!
I was unable to run this library without augmenting it:
tscodeshift -t dist/src/transforms/mocha.js 'my-fixture-file.ts'
Always resulted in:
node version:
v8.5.0
I also added a test to prove that this works as expected.
Please let me know if there are additional things you'd like me to change.