Closed Zolyn closed 1 year ago
Awesome, I was actually thinking about adding this the other day!
I made the structure of the test directory as follows:
test
├── common.test.ts // test file
├── fixtures
│ ├── common // category
│ │ ├── interface-extends-interface // scenario
│ │ │ └── no-reference // more detailed scenario
│ │ │ ├── index.ts // entry file (types)
│ │ ├── interface-without-reference
│ │ │ └── default
│ │ │ └── index.ts
│ │ └── redeclaration-of-types
│ │ └── default
│ │ └── index.ts
│ └── dynamic
│ └── interface-without-reference
│ └── default
│ ├── index.ts // the type file corresponding to the entry file
│ └── index.vue // entry file (code)
└── in-sfc.test.ts
Currently, I divided fixtures into two main categories:
"Common" means that all tests under this category are based on the same code, which corresponds to the scenario "use the imported type directly". Therefore, only type files are included under this category.
function generateCode(path: string): string {
return `<script lang="ts" setup>
import { Props } from '${path}'
defineProps<Props>()
</script>
`
}
"Dynamic" means that most of the tests under this category are based on different code. The most common scenario is "use the imported type indirectly". We need to read the content of the files and transform them.
Each detailed scenario can have multiple entry files to add more constraints.
We will test the entry files with different options, which means that each entry file has multiple tests.
Actually, I'm talking about the export name of each test in the snapshot file.
I imagine two ways of naming it.
Category > Scenario > Detailed scenario > entry file (options)
Example:
Common > Interface extends interface > No reference > index.ts (normal)
NOTE: The name of scenarios will be normalized. (e.g. interface-extends-interface
> Interface extends interface
)
Category > relative path of entry file > options
Example:
Common > interface-extends-interface/no-reference/index.ts > normal
Maybe I need to implement it and look at the output of running tests before I can decide which way to go. :P
transform
, we may need to test other functions in the future.I need suggestions (either it's naming, or whatever) to improve it before I implement it.
I don't think component testing will be necessary. We are mostly just doing basic transforms, so as long as we inspect that output after our transform and make sure everything is correct that should be good enough. Also component testing can be pretty complicated and heavy, so I think leaving it as vitest is well enough.
I don't think component testing will be necessary. We are mostly just doing basic transforms, so as long as we inspect that output after our transform and make sure everything is correct that should be good enough. Also component testing can be pretty complicated and heavy, so I think leaving it as vitest is well enough.
That's what I said. :D
I've also updated the comment, do you have any suggestions on it?
This is the error output of the two naming styles when the test encounters an error.
Which one do you think is better? If you have a better solution, feel free to suggest. :D
Hmm personally I find the first one a bit easier to read.
@wheatjs Done.
PR description is also updated.
See https://github.com/wheatjs/vite-plugin-vue-type-imports/pull/19#issuecomment-1203143020
Other changes
playground
)gitignore
to ignore directorycoverage
tsconfig.json
for better testing experiencetsup.config.ts
to remove some unnecessary fieldsprettier
and its configurations because it may conflict with antfu's eslint config (@antfu/eslint-config
)NOTE: This PR contains multiple commits, so it is recommended to use
Squash and merge
.