Skip to content

Copy only if the snap base file does exist. - #465

Merged
Pete Gonzalez (octogonz) merged 7 commits into
microsoft:masterfrom
lijunle:ts-snap
Mar 26, 2018
Merged

Pete Gonzalez (octogonz) merged 7 commits into
microsoft:masterfrom
lijunle:ts-snap

Conversation

@lijunle

@lijunle Junle Li (lijunle) commented Dec 28, 2017 •

Copy link
Copy Markdown
Member

The snapshot file name should respect the base file extension. If the test file is a.test.ts, the snapshot should name a.test.ts.snap. If the test file is b.test.tsx, the snapshot should name b.test.tsx.snap.

This issue is blocking run the official Jest CLI tool under projects.

http://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test

I suppose this is a bug of JestTask and name patch in rush change.

@octogonz

Copy link
Copy Markdown
Collaborator

Hey at Junle Li (@lijunle) , sorry we overlooked this PR. QZ (@qz2017) could you take a look?

@lijunle

Junle Li (lijunle) commented Mar 5, 2018 •

Copy link
Copy Markdown
Member Author

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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lijunle Junle Li (lijunle) Mar 13, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

@qz2017 QZ (qz2017) Mar 5, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'../../ [](start = 64, length = 7)

Is this always the same? Better use destRoot to construct it.

@lijunle Junle Li (lijunle) Mar 11, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using jest directly, you would not need to copy those files around. Those should be created at the desired location.

@lijunle Junle Li (lijunle) Mar 11, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@qz2017 QZ (qz2017) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

"changes": [
{
"packageName": "@microsoft/gulp-core-build",
"comment": "Respect the snapshot base file name.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Respect the snapshot base file name. [](start = 18, length = 36)

"Fix an issue where snapshot filenames did not follow Jest's naming convention."

@lijunle

Junle Li (lijunle) commented Mar 11, 2018 •

Copy link
Copy Markdown
Member Author

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

@qz2017

Copy link
Copy Markdown
Contributor

why do you rename this file?


Refers to: build-tests/web-library-build-test/src/test/snapshots/foo.test.ts.snap:4 in ce72400. [](commit_id = ce72400, deletion_comment = False)

@lijunle

Copy link
Copy Markdown
Member Author

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 .ts, so the snapshot file should be suffix with .ts.snap instead of .js.snap.

@lijunle

Copy link
Copy Markdown
Member Author

nickpape-msft I don't find a reason to not fix it.

@qz2017
QZ (qz2017) dismissed their stale review March 24, 2018 22:59

The change is trivial. It is okay to get it in and change later.

@qz2017 QZ (qz2017) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is small enough to be in to unblock Junle and be updated again in the future.

@lijunle

Junle Li (lijunle) commented Mar 26, 2018 •

Copy link
Copy Markdown
Member Author

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.

@octogonz
Pete Gonzalez (octogonz) merged commit a685126 into microsoft:master Mar 26, 2018
@lijunle
Junle Li (lijunle) deleted the ts-snap branch April 26, 2018 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants