Repository navigation
Copy only if the snap base file does exist. - #465
Conversation
|
Hey at Junle Li (@lijunle) , sorry we overlooked this PR. QZ (@qz2017) could you take a look? |
|
Hi, Pete Gonzalez (OLD ALIAS) (@pgonzal) nickpape-msft Ian Clanton-Thuon (@iclanton) Any chance to get this check-in? #Closed |
| globby.sync(pattern).forEach(sourceFile => { | ||
| const destination: string = sourceFile.replace(srcRoot, destRoot); | ||
| fsx.copySync(sourceFile, destination); | ||
| const jsDestination: string = destination.replace(/\.test\..+\.snap$/, '.test.js.snap'); |
There was a problem hiding this comment.
const jsDestination: string = destination.replace(/.test..+.snap$/, '.test.js.snap'); [](start = 6, length = 88)
Can you put { replace, check existing, and copy } into a function? So you can call the function four times instead of copying the code four times.
There was a problem hiding this comment.
Resolved. I cannot edit the status of the comment, even in CodeFlow.
In reply to: 172277005 [](ancestors = 172277005)
|
|
||
| private _doesSnapBaseFileExist(snapFilePath: string): boolean { | ||
| const fileName: string = path.basename(snapFilePath, '.snap'); | ||
| const snapBaseFilePath: string = path.resolve(snapFilePath, '../../', fileName); |
There was a problem hiding this comment.
'../../ [](start = 64, length = 7)
Is this always the same? Better use destRoot to construct it.
There was a problem hiding this comment.
This cannot be constructed from destRoot because that is only the root. The ../../ is used to go up from __snapshots__ folder. I will put a comment here. #Resolved
| const jsDestination: string = destination.replace(/\.test\..+\.snap$/, '.test.js.snap'); | ||
| const jsxDestination: string = destination.replace(/\.test\..+\.snap$/, '.test.jsx.snap'); | ||
| const tsDestination: string = destination.replace(/\.test\..+\.snap$/, '.test.ts.snap'); | ||
| const tsxDestination: string = destination.replace(/\.test\..+\.snap$/, '.test.tsx.snap'); |
There was a problem hiding this comment.
If you are using jest directly, you would not need to copy those files around. Those should be created at the desired location.
There was a problem hiding this comment.
QZ (@qz2017) This is not correct. Jest will complaint there there is out-of-dated snap file abc.test.js.snap then create a new one with name abc.test.ts.snap for me. However, I cannot check-in the ts one because it is breaking the gulp test build. #Resolved
| "changes": [ | ||
| { | ||
| "packageName": "@microsoft/gulp-core-build", | ||
| "comment": "Respect the snapshot base file name.", |
There was a problem hiding this comment.
Respect the snapshot base file name. [](start = 18, length = 36)
"Fix an issue where snapshot filenames did not follow Jest's naming convention."
|
QZ (@qz2017) Pete Gonzalez (OLD ALIAS) (@pgonzal) Thank you for the comments! I just resolved the comments. Could you please take a look again when you have time? Thank you! #Closed |
|
QZ (@qz2017) It is not to rename the file. The change of this file name is the intention of this fix - the original test file is suffix with |
|
nickpape-msft I don't find a reason to not fix it. |
The change is trivial. It is okay to get it in and change later.
QZ (qz2017)
left a comment
There was a problem hiding this comment.
The change is small enough to be in to unblock Junle and be updated again in the future.
|
QZ (@qz2017) Thanks very much for approving! nickpape-msft Pete Gonzalez (OLD ALIAS) (@pgonzal) Could you please help to merge the pull request? We can enjoy the fix in the next release. |
The snapshot file name should respect the base file extension. If the test file is
a.test.ts, the snapshot should namea.test.ts.snap. If the test file isb.test.tsx, the snapshot should nameb.test.tsx.snap.This issue is blocking run the official Jest CLI tool under projects.
I suppose this is a bug of JestTask and name patch in rush change.