Skip to content

Commit

Permalink
Exiting 1 if there is an error regardless of whether or not the --ver…
Browse files Browse the repository at this point in the history
…ify flag was passed
  • Loading branch information
jci-aws committed Sep 7, 2022
1 parent 5eaf83b commit f8d5945
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 129 deletions.
8 changes: 3 additions & 5 deletions src/embedme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,13 @@ sourceFiles.forEach((source, i) => {

const { outText, error } = embedme(sourceText, resolvedPath, options);

if (options.verify) {
if (error) {
process.exit(1);
} else if (options.verify) {
if (sourceText !== outText) {
errorLog(chalk => chalk.red(`Diff detected, exiting 1`));
process.exit(1);
}

if (error) {
process.exit(1);
}
} else if (options.stdout) {
process.stdout.write(outText);
} else if (!options.dryRun) {
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/fixture-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Missing File

```txt
// file-does-not-exist.txt
```

### Also bad file format

```ts
// also-not-a-file
```

### Contains Codefence

```md
<!-- contains-codefence.md -->
```

### Contains Codefence, but not the embedded lines

```md
<!-- contains-codefence.md#L1-L3 -->

# This markdown document

## Contains a codefence
```
28 changes: 0 additions & 28 deletions test/fixtures/fixture-in-place.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,34 +519,6 @@ Ignored block
// Not a file
```

### Also bad file format

```ts
// also-not-a-file
```

### Missing file

```txt
// this-file-does-not-exist.txt
```

### Contains Codefence

```md
<!-- contains-codefence.md -->
```

### Contains Codefence, but not the embedded lines

```md
<!-- contains-codefence.md#L1-L3 -->

# This markdown document

## Contains a codefence
```

### malformed line numbering

```ts
Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/fixture-missing.md

This file was deleted.

28 changes: 0 additions & 28 deletions test/fixtures/fixture-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,34 +287,6 @@ Ignored block
// Not a file
```

### Also bad file format

```ts
// also-not-a-file
```

### Missing file

```txt
// this-file-does-not-exist.txt
```

### Contains Codefence

```md
<!-- contains-codefence.md -->
```

### Contains Codefence, but not the embedded lines

```md
<!-- contains-codefence.md#L1-L3 -->

# This markdown document

## Contains a codefence
```

### malformed line numbering

```ts
Expand Down
28 changes: 0 additions & 28 deletions test/fixtures/fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,34 +519,6 @@ Ignored block
// Not a file
```

### Also bad file format

```ts
// also-not-a-file
```

### Missing file

```txt
// this-file-does-not-exist.txt
```

### Contains Codefence

```md
<!-- contains-codefence.md -->
```

### Contains Codefence, but not the embedded lines

```md
<!-- contains-codefence.md#L1-L3 -->

# This markdown document

## Contains a codefence
```

### malformed line numbering

```ts
Expand Down
36 changes: 2 additions & 34 deletions test/snapshots/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,34 +529,6 @@ Generated by [AVA](https://ava.li).
// Not a file␊
```␊
### Also bad file format␊
```ts␊
// also-not-a-file␊
```␊
### Missing file␊
```txt␊
// this-file-does-not-exist.txt␊
```␊
### Contains Codefence␊
```md␊
<!-- contains-codefence.md -->␊
```␊
### Contains Codefence, but not the embedded lines␊
```md␊
<!-- contains-codefence.md#L1-L3 -->␊
# This markdown document␊
## Contains a codefence␊
```␊
### malformed line numbering␊
```ts␊
Expand Down Expand Up @@ -621,12 +593,8 @@ Generated by [AVA](https://ava.li).
test/fixtures/fixture-in-place.md#L506-L508 Unsupported file extension [binary], supported extensions are txt, ts, js, re, scss, rust, java, cpp, c, html, xml, md, yaml, json, json5, py, bash, sh, go, objectivec, php, cs, swift, rb, kotlin, scala, cr, puml, mermaid, cmake, proto, sql, hs, ino, jsx, tsx, skipping code block␊
test/fixtures/fixture-in-place.md#L512-L514 No code extension detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L518-L520 No comment detected in first line for block with extension ts␊
test/fixtures/fixture-in-place.md#L524-L526 Found filename also-not-a-file in comment in first line, but file does not exist at ${cwd}/test/fixtures/also-not-a-file!␊
test/fixtures/fixture-in-place.md#L530-L532 Found filename this-file-does-not-exist.txt in comment in first line, but file does not exist at ${cwd}/test/fixtures/this-file-does-not-exist.txt!␊
test/fixtures/fixture-in-place.md#L536-L538 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L542-L548 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L552-L554 Incorrectly formatted line numbering string snippets/sample.ts#L1-2, Expecting Github formatting e.g. #L10-L20␊
test/fixtures/fixture-in-place.md#L558-L560 Code block is empty & no preceding embedme comment, skipping...␊
test/fixtures/fixture-in-place.md#L524-L526 Incorrectly formatted line numbering string snippets/sample.ts#L1-2, Expecting Github formatting e.g. #L10-L20␊
test/fixtures/fixture-in-place.md#L530-L532 Code block is empty & no preceding embedme comment, skipping...␊
Writing test/fixtures/fixture-in-place.md with embedded changes.␊
`

Expand Down
Binary file modified test/snapshots/test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('it strips embedded comments', async t => {

test('it exits with code 1 when a file does not exist with --verify', async t => {
const error: Error & { code: number } = await t.throwsAsync(
execAsync(`node dist/embedme.js test/fixtures/fixture-missing.md --verify`),
execAsync(`node dist/embedme.js test/fixtures/fixture-error.md --verify`),
);

t.assert(error.code === 1);
Expand Down

0 comments on commit f8d5945

Please sign in to comment.