Skip to content
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

test: Add more sample data for testing Cache - and streamline its creation #2841

Merged
merged 24 commits into from
May 21, 2024

Conversation

claremacrae
Copy link
Collaborator

@claremacrae claremacrae commented May 20, 2024

Description

New test data:

  • Add more sample Markdown files to the Tasks-Demo vault, in Test Data/*.md
  • Add TypeScript versions of these files in tests/Obsidian/__test_data__/*.ts

Streamlined creation and processing of this test data:

  • Add a Templater template that may help with creating a new file, for single-tasks cases: resources/sample_vaults/Tasks-Demo/_meta/templates/Test Data file.md
  • Add a Templater script mechanism to convert these markdown files to TypeScript
    • resources/sample_vaults/Tasks-Demo/_meta/templater_scripts/convert_test_data_markdown_to_js.js
      • The code to do the conversion
    • resources/sample_vaults/Tasks-Demo/_meta/templates/convert_test_data_markdown_to_js.md
      • Template file that executes the conversion
  • Install the 'Broken Links' plugin to find and fix any accidentally broken links

Note: sometimes editing the Markdown can change the order of the fields in the generated .ts file - e.g. see f40fe32. This is irritating but harmless.


See the updated instructions in Cache.test.ts for how to use this new mechanism:

Test creation sequence

  • Create a sample markdown file in Tasks demo vault (root/Test Data/) with the simplest content
    to represent your test case. Choose a meaningful file name in snake case. See example in Test Data/one_task.md.
    • There is a Templater template that may help with creating a new file, for single-tasks cases:
      resources/sample_vaults/Tasks-Demo/_meta/templates/Test Data file.md
  • Open any other note in Source or 'Live Preview' modes
  • Run the command Templater: Insert _meta/templates/convert_test_data_markdown_to_js.md
    • Or type the short-cut Ctrl + Cmd + Alt + T / Ctrl + Ctrl + Alt + T
  • This will convert all the files root/Test Data/*.md to test functions in tests/Obsidian/__test_data__/*.ts
  • Run yarn lint to standardise the formatting in the generated TypeScript files.
  • Use the data in the test with readTasksFromSimulatedFile(), the argument is the constant you
    created in the previous step.
  • Remember to commit the markdown file in the demo vault and the file with the simulated data.

Motivation and Context

  • Make creation of test data more streamlined and reliable

How has this been tested?

  • By running the new script and reviewing the generated files.

Screenshots (if appropriate)

Types of changes

Internal changes:

  • Tests (prefix: test - additions and improvements to unit tests and the smoke tests)

Checklist

  • My code follows the code style of this project and passes yarn run lint.
  • My change requires a change to the documentation.
    • Comments in Cache.test.ts should be moved to the Contributing site at some point
  • I have updated the documentation accordingly.
  • My change has adequate Unit Test coverage.

Terms

They are not all about frontmatter, and there will be overlapping concerns
This shows that the order of the machine-generated may not be
stable after running through 'yarn lint'.
@claremacrae claremacrae added the type: internal Only regards development or contributing label May 20, 2024
@claremacrae claremacrae changed the title test: Add more sample data for testing Cache test: Add more sample data for testing Cache - and streamline its creation May 20, 2024
@claremacrae
Copy link
Collaborator Author

Hi @ilandikov - the commit history is a mess on this, so I think I will probably squash it...

But I am hoping that this will save you and Stanislav some time and ensure consistency - so it would really help if you could try out this new scripting mechanism on Tuesday and see if it works for you...

@claremacrae
Copy link
Collaborator Author

I've fixed the formatting in the description.

@ilandikov
Copy link
Collaborator

But I am hoping that this will save you and Stanislav some time and ensure consistency - so it would really help if you could try out this new scripting mechanism on Tuesday and see if it works for you...

Just to be clear, you mean that we can reuse the new scripting mechanism to quickly create the files with test data from markdown files?

Also, what is the role of broken links plugin? =)

@claremacrae
Copy link
Collaborator Author

But I am hoping that this will save you and Stanislav some time and ensure consistency - so it would really help if you could try out this new scripting mechanism on Tuesday and see if it works for you...

Just to be clear, you mean that we can reuse the new scripting mechanism to quickly create the files with test data from markdown files?

Yes exactly...

Also, what is the role of broken links plugin? =)

Some of the test files I added had accidentally-broken-links in them, and I wanted it to be visible so I could fix them.

I'd added the plugin to the two documentation vaults previously, but never this one...

@claremacrae
Copy link
Collaborator Author

Does the mechanism work for you? Can you try adding a new .md file and see the .ts file created?

@claremacrae
Copy link
Collaborator Author

I thought of an improvement to the script.

Currently it writes text out to the active note, which needs to be undone.

I could instead use a Notice.

@ilandikov
Copy link
Collaborator

Feedback:

  • on this action: Run the command 'Templater: Insert _meta/templates/convert_test_data_markdown_to_js.md' I had to grant Obsidian.app access to my Documents folder
  • after running that command ALL the ts files in test/Obsidian/__test_data__ were modified
  • I did not find my test file in that
  • I would definitely move Success - now run "yarn lint" to format the generated files. to a notification =)

@claremacrae
Copy link
Collaborator Author

I did not find my test file in that

What did you mean by that? It sounds serious
Did you refresh in WebStorm's Commit view?

@ilandikov
Copy link
Collaborator

What did you mean by that? It sounds serious Did you refresh in WebStorm's Commit view?

Sorry, I was wrong and found the issue on my side. Just tried the sequence again. It turns out that the md file has to be in the Test Data folder which I forgot. I suggest showing an error message if the templater command is run on a file in a different folder or maybe move the file to that folder.

Anyways after the command all my ts were modified, the new files are in Unversioned files:
Снимок экрана 2024-05-21 в 16 14 25

After I ran the yarn lint command, here is the state I got:
Снимок экрана 2024-05-21 в 16 15 06

@ilandikov
Copy link
Collaborator

ilandikov commented May 21, 2024

Also please note that the text in the md file is appended to the cursor position, not on a new line:
Снимок экрана 2024-05-21 в 16 19 16
(a few moments later...)
Снимок экрана 2024-05-21 в 16 19 27

@claremacrae
Copy link
Collaborator Author

Thank you for the feedback, it was really helpful.

I've changed it so that:

  • the open markdown file is now not edited at all
  • the instruction to run yarn lint is shown in a Notice
  • and that one existing file which was showing as changed is now saved in its new formatting

I need to put this down, so will merge (well, squash) it.

@ilandikov
Copy link
Collaborator

Just tried the latest version on my side - this is so much better =) Thanks!

@claremacrae claremacrae merged commit e16f543 into main May 21, 2024
2 checks passed
@claremacrae claremacrae deleted the add-frontmatter-sample-data branch May 21, 2024 16:10
@claremacrae
Copy link
Collaborator Author

I've added a new run option to package.json to speed up iterating on test data: 64d87e0

yarn lint:test-data

@ilandikov
Copy link
Collaborator

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: internal Only regards development or contributing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants