-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e9989f2
Showing
60 changed files
with
9,178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"100": true, | ||
"reporter": ["html", "lcov", "text"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 100 | ||
trim_trailing_whitespace = true | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 72 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
root: true | ||
extends: | ||
- remcohaszing | ||
- remcohaszing/typechecking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: ci | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
tags: ['*'] | ||
|
||
jobs: | ||
eslint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npx eslint . | ||
|
||
pack: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npm pack | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: package | ||
path: '*.tgz' | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 16 | ||
- 18 | ||
- 20 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- run: node --test | ||
if: ${{ matrix.node-version == 16 }} | ||
- run: npm test | ||
if: ${{ matrix.node-version >= 18 }} | ||
- uses: codecov/codecov-action@v4 | ||
if: ${{ matrix.node-version == 20 }} | ||
|
||
prettier: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npx prettier --check . | ||
|
||
remark: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npx remark --frail . | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- eslint | ||
- test | ||
- pack | ||
- prettier | ||
- remark | ||
if: startsWith(github.ref, 'refs/tags/') | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org | ||
- uses: actions/download-artifact@v4 | ||
with: { name: package } | ||
- run: npm publish *.tgz --provenance --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage/ | ||
dist/ | ||
node_modules/ | ||
*.log | ||
*.tsbuildinfo | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
proseWrap: always | ||
semi: false | ||
singleQuote: true | ||
trailingComma: none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
plugins: | ||
- remark-preset-remcohaszing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# MIT License | ||
|
||
Copyright © 2024 Remco Haszing | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
associated documentation files (the “Software”), to deal in the Software without restriction, | ||
including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial | ||
portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES | ||
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# snapshot-fixtures | ||
|
||
[![github actions](https://github.com/remcohaszing/snapshot-fixtures/actions/workflows/ci.yaml/badge.svg)](https://github.com/remcohaszing/snapshot-fixtures/actions/workflows/ci.yaml) | ||
[![codecov](https://codecov.io/gh/remcohaszing/snapshot-fixtures/branch/main/graph/badge.svg)](https://codecov.io/gh/remcohaszing/snapshot-fixtures) | ||
[![npm version](https://img.shields.io/npm/v/snapshot-fixtures)](https://www.npmjs.com/package/snapshot-fixtures) | ||
[![npm downloads](https://img.shields.io/npm/dm/snapshot-fixtures)](https://www.npmjs.com/package/snapshot-fixtures) | ||
|
||
Snapshot fixtures for [`node:test`](https://nodejs.org/api/test.html). | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [When to use this?](#when-to-use-this) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [`assertEqual(actual, expected[, options])`](#assertequalactual-expected-options) | ||
- [Arguments](#arguments) | ||
- [`testFixturesDirectory(options)`](#testfixturesdirectoryoptions) | ||
- [Options](#options) | ||
- [`Test`](#test) | ||
- [Compatibility](#compatibility) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install snapshot-fixtures | ||
``` | ||
|
||
## When to use this? | ||
|
||
This package exposes a function for creating tests based on a directory containing test fixtures. | ||
This is useful if you want to run tests based on a string input and a string output, especially for | ||
multiline content. | ||
|
||
## Usage | ||
|
||
Let’s say you have the following project structure: | ||
|
||
``` | ||
my-project/ | ||
├── fixtures | ||
│ ├── fixture-1 | ||
│ │ ├── input.txt | ||
│ │ ├── expected-1.txt | ||
│ │ ├── expected-2.txt | ||
│ │ └── options.json | ||
│ └── fixture-2 | ||
│ ├── input.txt | ||
│ ├── expected-1.txt | ||
│ ├── expected-2.txt | ||
│ └── options.js | ||
└── test | ||
└── fixtures.test.js | ||
``` | ||
|
||
Then `src/fixtures.test.js` could look like this: | ||
|
||
```typescript | ||
import { fn } from 'my-project' | ||
import { testFixturesDirectory } from 'snapshot-fixtures' | ||
|
||
testFixturesDirectory({ | ||
directory: new URL('../fixtures', import.meta.url), | ||
tests: { | ||
'expected-1.txt'(file, options) { | ||
return fn(file, options) | ||
}, | ||
|
||
'expected-2.txt'(file, options) { | ||
return fn(file, options, 'additional options') | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
This test asserts that the contents of the `expected-1.txt` and `expected-2.txt` tests of each | ||
fixture match the respective return value of matching test function. | ||
|
||
## API | ||
|
||
### `assertEqual(actual, expected[, options])` | ||
|
||
Assert two strings are equal. | ||
|
||
If the strings are not equal, an assertion error will be thrown. This assertion error contains a | ||
pretty diff of the two strings. | ||
|
||
#### Arguments | ||
|
||
- `actual` (`string`) — The actual value that was produced. | ||
- `expected` (`string`) — The value that was expected. | ||
- `options` (`object`, optional) — An object with additional options. The following options are | ||
supported: | ||
- `url` (`string` | `URL`) — The file URL to include in the assertion error if `expected` is not | ||
equal to `actual`. | ||
|
||
### `testFixturesDirectory(options)` | ||
|
||
Create a test suite for a fixtures directory based on | ||
[`node:test`](https://nodejs.org/api/test.html). A fixtures directory is a directory that contains | ||
other directories. For each of these directories a nested test suite is created. For each of these | ||
nested test suites, a test is created based on the tests passed. Each test reads the input file, | ||
uses the given test function to generate output, and compares it to the content of the expected | ||
output file. | ||
|
||
#### Options | ||
|
||
- `directory` (`string` | `URL`) — The directory containing fixtures as a URL or URL string. | ||
- `prettier` (`boolean`, optional) — If true, format the generated value with Prettier. (Default: | ||
false) | ||
- `tests` (`object`) — A mapping of test name to a [fixture test](#test). | ||
- `write` (`boolean`) — If true, overwrite the expected content with the actual content. In CI, the | ||
output is never written. (Default: false) | ||
|
||
### `Test` | ||
|
||
A test to run, either as a fixture test object, or as a generate function. The generate function | ||
takes a [`VFile`](https://github.com/vfile/vfile) as input, which is read from the `input` file and | ||
return a string that should match the expected output. A second argument `options` can be accepted. | ||
This may contain the options of the fixture. These options are read from the `options.cjs`, | ||
`options.js`, `options.json` or `options.mjs` file in the fixture directory. | ||
|
||
A test may be an object with the `generate` and optional `input`, `expected` properties. In this | ||
case `input` determines which input file to read, `generate` serves as the generate function, and | ||
`expected` refers to the expected output file. | ||
|
||
## Compatibility | ||
|
||
This project is compatible with Node.js 16 or greater. | ||
|
||
## License | ||
|
||
[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Trailing slash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file exists to test that plain files are skipped. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.options = 'cjs' |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": "cjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Trailing slash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
options: 'js' | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": "js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Trailing slash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": "json" | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": "json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Trailing slash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Custom input and output |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
options: 'mjs' | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"options": "mjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Trailing slash |
Oops, something went wrong.