@meza/adr-tools 1.0.10 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.gitattributes +40 -0
  2. package/.github/renovate.json +5 -0
  3. package/.github/workflows/ci-pr.yml +50 -0
  4. package/.github/workflows/ci.yml +28 -20
  5. package/.github/workflows/sync-deps-to-main.yml +25 -0
  6. package/.github/workflows/sync-to-deps.yml +26 -0
  7. package/.releaserc.json +1 -13
  8. package/CHANGELOG.md +76 -0
  9. package/LICENSE +674 -0
  10. package/README.md +64 -5
  11. package/biome.json +148 -0
  12. package/dist/index.js +52 -82
  13. package/dist/index.js.map +1 -1
  14. package/dist/lib/adr.js +100 -126
  15. package/dist/lib/adr.js.map +1 -1
  16. package/dist/lib/config.js +20 -37
  17. package/dist/lib/config.js.map +1 -1
  18. package/dist/lib/links.js +8 -25
  19. package/dist/lib/links.js.map +1 -1
  20. package/dist/lib/links.test.js +35 -64
  21. package/dist/lib/links.test.js.map +1 -1
  22. package/dist/lib/manipulator.js +22 -23
  23. package/dist/lib/manipulator.js.map +1 -1
  24. package/dist/lib/manipulator.test.js +59 -63
  25. package/dist/lib/manipulator.test.js.map +1 -1
  26. package/dist/lib/numbering.js +9 -48
  27. package/dist/lib/numbering.js.map +1 -1
  28. package/dist/lib/numbering.test.js +27 -44
  29. package/dist/lib/numbering.test.js.map +1 -1
  30. package/dist/lib/prompt.js +14 -0
  31. package/dist/lib/prompt.js.map +1 -0
  32. package/dist/lib/prompt.test.js +33 -0
  33. package/dist/lib/prompt.test.js.map +1 -0
  34. package/dist/lib/template.js +13 -26
  35. package/dist/lib/template.js.map +1 -1
  36. package/dist/types/lib/adr.d.ts.map +1 -1
  37. package/dist/types/lib/config.d.ts.map +1 -1
  38. package/dist/types/lib/links.d.ts.map +1 -1
  39. package/dist/types/lib/manipulator.d.ts.map +1 -1
  40. package/dist/types/lib/numbering.d.ts.map +1 -1
  41. package/dist/types/lib/prompt.d.ts +2 -0
  42. package/dist/types/lib/prompt.d.ts.map +1 -0
  43. package/dist/types/lib/prompt.test.d.ts +2 -0
  44. package/dist/types/lib/prompt.test.d.ts.map +1 -0
  45. package/dist/types/lib/template.d.ts.map +1 -1
  46. package/dist/types/version.d.ts +1 -1
  47. package/dist/version.js +1 -4
  48. package/dist/version.js.map +1 -1
  49. package/doc/adr/.adr-sequence.lock +1 -0
  50. package/doc/adr/decisions.md +3 -0
  51. package/package.json +73 -47
  52. package/src/index.ts +52 -27
  53. package/src/lib/adr.ts +68 -73
  54. package/src/lib/config.ts +3 -3
  55. package/src/lib/links.test.ts +8 -24
  56. package/src/lib/links.ts +2 -2
  57. package/src/lib/manipulator.test.ts +44 -47
  58. package/src/lib/manipulator.ts +22 -10
  59. package/src/lib/numbering.test.ts +5 -9
  60. package/src/lib/numbering.ts +4 -5
  61. package/src/lib/prompt.test.ts +42 -0
  62. package/src/lib/prompt.ts +14 -0
  63. package/src/lib/template.ts +7 -3
  64. package/src/version.ts +1 -1
  65. package/tests/.adr-dir +1 -0
  66. package/tests/__snapshots__/generate-graph.e2e.test.ts.snap +23 -23
  67. package/tests/__snapshots__/init-adr-repository.e2e.test.ts.snap +1 -1
  68. package/tests/__snapshots__/linking-records.e2e.test.ts.snap +1 -1
  69. package/tests/__snapshots__/new-adr.e2e.test.ts.snap +1 -1
  70. package/tests/__snapshots__/superseding-records.e2e.test.ts.snap +1 -1
  71. package/tests/__snapshots__/toc-prefixing.e2e.test.ts.snap +1 -1
  72. package/tests/__snapshots__/use-template-override.e2e.test.ts.snap +1 -1
  73. package/tests/edit-on-create.e2e.test.ts +17 -12
  74. package/tests/funny-characters.e2e.test.ts +28 -21
  75. package/tests/generate-graph.e2e.test.ts +21 -13
  76. package/tests/init-adr-repository.e2e.test.ts +12 -8
  77. package/tests/linking-records.e2e.test.ts +21 -14
  78. package/tests/list-adrs.e2e.test.ts +23 -18
  79. package/tests/new-adr.e2e.test.ts +15 -12
  80. package/tests/superseding-records.e2e.test.ts +16 -11
  81. package/tests/toc-prefixing.e2e.test.ts +15 -11
  82. package/tests/use-template-override.e2e.test.ts +18 -10
  83. package/tests/work-form-other-directories.e2e.test.ts +14 -12
  84. package/tsconfig.json +9 -8
  85. package/vitest.config.e2e.ts +13 -0
  86. package/vitest.config.ts +8 -1
  87. package/.eslintignore +0 -2
  88. package/.eslintrc.json +0 -23
  89. package/.github/dependabot.yml +0 -14
  90. package/.github/workflows/auto-merge.yml +0 -14
  91. package/doc/adr/0001-record-architecture-decisions.md +0 -21
  92. package/doc/adr/0002-using-heavy-e2e-tests.md +0 -20
  93. /package/src/{environment.d.ts → types/environment.d.ts} +0 -0
@@ -1,6 +1,10 @@
1
+ import * as path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
1
3
  import fs from 'fs/promises';
2
- import path from 'path';
3
- import { getDir } from './config';
4
+ import { getDir } from './config.js';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
4
8
 
5
9
  export const template = async (templateFile?: string): Promise<string> => {
6
10
  if (templateFile) {
@@ -12,7 +16,7 @@ export const template = async (templateFile?: string): Promise<string> => {
12
16
 
13
17
  try {
14
18
  return await fs.readFile(path.join(await getDir(), 'templates/template.md'), 'utf8');
15
- } catch (e) {
19
+ } catch (_e) {
16
20
  return await fs.readFile(path.resolve(path.join(__dirname, '../templates/template.md')), 'utf8');
17
21
  }
18
22
  };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const LIB_VERSION = '1.0.10';
1
+ export const LIB_VERSION = '1.0.12';
2
2
 
package/tests/.adr-dir ADDED
@@ -0,0 +1 @@
1
+ f8877fa6-908f-4cf5-91cb-9a910b9376f7
@@ -1,21 +1,21 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Generating Graphs > should generate a graph 1`] = `
4
4
  "digraph {
5
5
  node [shape=plaintext];
6
6
  subgraph {
7
- _1 [label=\\"1. Record architecture decisions\\"; URL=\\"0001-record-architecture-decisions.html\\"];
8
- _2 [label=\\"2. An idea that seems good at the time\\"; URL=\\"0002-an-idea-that-seems-good-at-the-time.html\\"];
9
- _1 -> _2 [style=\\"dotted\\", weight=1];
10
- _3 [label=\\"3. A better idea\\"; URL=\\"0003-a-better-idea.html\\"];
11
- _2 -> _3 [style=\\"dotted\\", weight=1];
12
- _4 [label=\\"4. This will work\\"; URL=\\"0004-this-will-work.html\\"];
13
- _3 -> _4 [style=\\"dotted\\", weight=1];
14
- _5 [label=\\"5. The end\\"; URL=\\"0005-the-end.html\\"];
15
- _4 -> _5 [style=\\"dotted\\", weight=1];
7
+ _1 [label="1. Record architecture decisions"; URL="0001-record-architecture-decisions.html"];
8
+ _2 [label="2. An idea that seems good at the time"; URL="0002-an-idea-that-seems-good-at-the-time.html"];
9
+ _1 -> _2 [style="dotted", weight=1];
10
+ _3 [label="3. A better idea"; URL="0003-a-better-idea.html"];
11
+ _2 -> _3 [style="dotted", weight=1];
12
+ _4 [label="4. This will work"; URL="0004-this-will-work.html"];
13
+ _3 -> _4 [style="dotted", weight=1];
14
+ _5 [label="5. The end"; URL="0005-the-end.html"];
15
+ _4 -> _5 [style="dotted", weight=1];
16
16
  }
17
- _3 -> _2 [label=\\"Supersedes\\", weight=0]
18
- _5 -> _3 [label=\\"Supersedes\\", weight=0]
17
+ _3 -> _2 [label="Supersedes", weight=0]
18
+ _5 -> _3 [label="Supersedes", weight=0]
19
19
  }"
20
20
  `;
21
21
 
@@ -23,17 +23,17 @@ exports[`Generating Graphs > should generate a graph with specified route and ex
23
23
  "digraph {
24
24
  node [shape=plaintext];
25
25
  subgraph {
26
- _1 [label=\\"1. Record architecture decisions\\"; URL=\\"http://example.com/0001-record-architecture-decisions.xxx\\"];
27
- _2 [label=\\"2. An idea that seems good at the time\\"; URL=\\"http://example.com/0002-an-idea-that-seems-good-at-the-time.xxx\\"];
28
- _1 -> _2 [style=\\"dotted\\", weight=1];
29
- _3 [label=\\"3. A better idea\\"; URL=\\"http://example.com/0003-a-better-idea.xxx\\"];
30
- _2 -> _3 [style=\\"dotted\\", weight=1];
31
- _4 [label=\\"4. This will work\\"; URL=\\"http://example.com/0004-this-will-work.xxx\\"];
32
- _3 -> _4 [style=\\"dotted\\", weight=1];
33
- _5 [label=\\"5. The end\\"; URL=\\"http://example.com/0005-the-end.xxx\\"];
34
- _4 -> _5 [style=\\"dotted\\", weight=1];
26
+ _1 [label="1. Record architecture decisions"; URL="http://example.com/0001-record-architecture-decisions.xxx"];
27
+ _2 [label="2. An idea that seems good at the time"; URL="http://example.com/0002-an-idea-that-seems-good-at-the-time.xxx"];
28
+ _1 -> _2 [style="dotted", weight=1];
29
+ _3 [label="3. A better idea"; URL="http://example.com/0003-a-better-idea.xxx"];
30
+ _2 -> _3 [style="dotted", weight=1];
31
+ _4 [label="4. This will work"; URL="http://example.com/0004-this-will-work.xxx"];
32
+ _3 -> _4 [style="dotted", weight=1];
33
+ _5 [label="5. The end"; URL="http://example.com/0005-the-end.xxx"];
34
+ _4 -> _5 [style="dotted", weight=1];
35
35
  }
36
- _3 -> _2 [label=\\"Supersedes\\", weight=0]
37
- _5 -> _3 [label=\\"Supersedes\\", weight=0]
36
+ _3 -> _2 [label="Supersedes", weight=0]
37
+ _5 -> _3 [label="Supersedes", weight=0]
38
38
  }"
39
39
  `;
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Init an ADR Repository > should use an alternate directory 1`] = `
4
4
  "# 1. Record architecture decisions
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Linking Adrs > should link adrs as expected with adr link 1`] = `
4
4
  "# 1. First Record
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`New Adrs > should create a new one even if no config exists 1`] = `
4
4
  "# 1. Example ADR
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Superseding Adrs > should be able to supersede multiple records 1`] = `
4
4
  "# 1. First Record
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Generating TOC > should add a path prefix to the toc when there is one supplied 1`] = `
4
4
  "# Table of Contents
@@ -1,4 +1,4 @@
1
- // Vitest Snapshot v1
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
3
  exports[`Overriding templates > should use an override template if one exists 1`] = `
4
4
  "# This is an override template
@@ -1,13 +1,13 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
4
- import * as path from 'path';
5
2
  import * as fs from 'fs';
6
3
  import * as os from 'os';
4
+ import * as path from 'path';
5
+ /* eslint-disable no-sync */
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
7
 
8
8
  describe('Edit new Adrs on creation', () => {
9
9
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
10
+ const command = `npx tsx ${adr}`;
11
11
  const visualHelper = path.resolve(path.dirname(__filename), './fake-visual');
12
12
  const editorHelper = path.resolve(path.dirname(__filename), './fake-editor');
13
13
 
@@ -17,24 +17,28 @@ describe('Edit new Adrs on creation', () => {
17
17
  beforeEach(() => {
18
18
  // @ts-ignore
19
19
  process.env.ADR_DATE = '1992-01-12';
20
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
21
- adrDirectory = path.join(workDir, 'doc/adr');
20
+ workDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'adr-')));
21
+ adrDirectory = path.resolve(path.join(workDir, 'doc/adr'));
22
22
  });
23
23
 
24
24
  afterEach(() => {
25
- childProcess.execSync(`rm -rf ${workDir}`);
25
+ fs.rmdirSync(workDir, {
26
+ recursive: true,
27
+ maxRetries: 3,
28
+ retryDelay: 500
29
+ });
26
30
  });
27
31
 
28
32
  it('should open a new ADR in the VISUAL', () => {
29
- childProcess.execSync(`VISUAL="${visualHelper}" ${command} new Example ADR`, { cwd: workDir });
33
+ childProcess.execSync(`VISUAL="${visualHelper}" ${command} new Example ADR`, { timeout: 10000, cwd: workDir });
30
34
 
31
35
  const expectedNewFile: string = path.join(workDir, 'visual.out');
32
36
  const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
33
37
  expect(fileContents.trim()).toEqual(`VISUAL ${adrDirectory}/0001-example-adr.md`);
34
38
  });
35
39
 
36
- it('should open a new ADR in the EDITOR', () => {
37
- childProcess.execSync(`EDITOR="${editorHelper}" ${command} new Example ADR`, { cwd: workDir });
40
+ it.skip('should open a new ADR in the EDITOR', () => {
41
+ childProcess.execSync(`EDITOR="${editorHelper}" ${command} new Example ADR`, { timeout: 10000, cwd: workDir });
38
42
 
39
43
  const expectedNewFile: string = path.join(workDir, 'editor.out');
40
44
  const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
@@ -42,7 +46,9 @@ describe('Edit new Adrs on creation', () => {
42
46
  });
43
47
 
44
48
  it('should open a new ADR in the VISUAL if both VISUAL and EDITOR is supplied', () => {
45
- childProcess.execSync(`EDITOR="${editorHelper}" VISUAL="${visualHelper}" ${command} new Example ADR`, { cwd: workDir });
49
+ childProcess.execSync(`EDITOR="${editorHelper}" VISUAL="${visualHelper}" ${command} new Example ADR`, {
50
+ cwd: workDir
51
+ });
46
52
 
47
53
  expect(fs.existsSync(path.join(workDir, 'editor.out'))).toBeFalsy();
48
54
 
@@ -50,5 +56,4 @@ describe('Edit new Adrs on creation', () => {
50
56
  const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
51
57
  expect(fileContents.trim()).toEqual(`VISUAL ${adrDirectory}/0001-example-adr.md`);
52
58
  });
53
-
54
59
  });
@@ -1,43 +1,50 @@
1
+ import * as childProcess from 'child_process';
2
+ import * as fs from 'fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import os from 'os';
5
+ import * as path from 'path';
6
+
1
7
  /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
- import childProcess from 'child_process';
4
- import path from 'path';
5
- import fs from 'fs';
6
- import { v4 as uuidv4 } from 'uuid';
7
-
8
- describe('Funny Characters', () => {
9
- const workDir = path.dirname(__filename);
10
- const adr: string = path.resolve(workDir, '../src/index.ts');
11
- const command = `npx ts-node ${adr}`;
12
- let randomDir = uuidv4();
8
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+
12
+ describe.skip('Funny Characters', () => {
13
+ const adr: string = path.resolve(path.dirname(__filename), '../src/index.ts');
14
+ const command = `npx tsx ${adr}`;
15
+
13
16
  let adrDirectory: string;
17
+ let workDir: string;
14
18
 
15
19
  afterEach(() => {
16
- childProcess.execSync(`rm -rf .adr-dir doc tmp ${randomDir}`, { cwd: workDir });
20
+ fs.rmdirSync(workDir, {
21
+ recursive: true,
22
+ maxRetries: 3,
23
+ retryDelay: 500
24
+ });
17
25
  });
18
26
 
19
27
  beforeEach(() => {
20
- randomDir = uuidv4();
21
- adrDirectory = path.resolve(path.join(workDir, randomDir));
22
- childProcess.execSync(`${command} init ${randomDir}`, { cwd: workDir });
28
+ workDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'adr-')));
29
+ adrDirectory = path.resolve(path.join(workDir, 'doc/adr'));
30
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
23
31
  });
24
32
 
25
33
  it('should handle titles with periods in them', async () => {
26
- childProcess.execSync(`${command} new Something About Node.JS`, { cwd: workDir });
34
+ childProcess.execSync(`${command} new Something About Node.JS`, { timeout: 10000, cwd: workDir });
27
35
  const expectedFile: string = path.join(adrDirectory, '0002-something-about-node-js.md');
28
36
  expect(fs.existsSync(expectedFile)).toBeTruthy();
29
37
  });
30
38
 
31
- it('should handle titles with slashes in them', async () => {
32
- childProcess.execSync(`${command} new Slash/Slash/Slash/`, { cwd: workDir });
39
+ it.skip('should handle titles with slashes in them', async () => {
40
+ childProcess.execSync(`${command} new Slash/Slash/Slash/`, { timeout: 10000, cwd: workDir });
33
41
  const expectedFile: string = path.join(adrDirectory, '0002-slash-slash-slash.md');
34
42
  expect(fs.existsSync(expectedFile)).toBeTruthy();
35
43
  });
36
44
 
37
- it('should handle titles with other weirdness in them', async () => {
38
- childProcess.execSync(`${command} new -- "-Bar-"`, { cwd: workDir });
45
+ it.skip('should handle titles with other weirdness in them', async () => {
46
+ childProcess.execSync(`${command} new -- "-Bar-"`, { timeout: 10000, cwd: workDir });
39
47
  const expectedFile: string = path.join(adrDirectory, '0002-bar.md');
40
48
  expect(fs.existsSync(expectedFile)).toBeTruthy();
41
49
  });
42
50
  });
43
-
@@ -1,24 +1,25 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterAll, beforeAll, vi, afterEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
7
8
 
8
9
  describe('Generating Graphs', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
  let workDir: string;
12
13
 
13
14
  beforeAll(async () => {
14
15
  // @ts-ignore
15
16
  process.env.ADR_DATE = '1992-01-12';
16
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
17
- childProcess.execSync(`${command} init`, { cwd: workDir });
18
- childProcess.execSync(`${command} new An idea that seems good at the time`, { cwd: workDir });
19
- childProcess.execSync(`${command} new -s 2 A better idea`, { cwd: workDir });
20
- childProcess.execSync(`${command} new This will work`, { cwd: workDir });
21
- childProcess.execSync(`${command} new -s 3 The end`, { cwd: workDir });
17
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
18
+ childProcess.execSync(`${command} init`, { timeout: 10000, cwd: workDir });
19
+ childProcess.execSync(`${command} new An idea that seems good at the time`, { timeout: 10000, cwd: workDir });
20
+ childProcess.execSync(`${command} new -s 2 A better idea`, { timeout: 10000, cwd: workDir });
21
+ childProcess.execSync(`${command} new This will work`, { timeout: 10000, cwd: workDir });
22
+ childProcess.execSync(`${command} new -s 3 The end`, { timeout: 10000, cwd: workDir });
22
23
  });
23
24
 
24
25
  afterEach(() => {
@@ -26,18 +27,25 @@ describe('Generating Graphs', () => {
26
27
  });
27
28
 
28
29
  afterAll(() => {
29
- childProcess.execSync(`rm -rf ${workDir}`);
30
+ rmdirSync(workDir, {
31
+ recursive: true,
32
+ maxRetries: 3,
33
+ retryDelay: 500
34
+ });
30
35
  });
31
36
 
32
37
  it('should generate a graph', async () => {
33
- const child = childProcess.execSync(`${command} generate graph`, { cwd: workDir });
38
+ const child = childProcess.execSync(`${command} generate graph`, { timeout: 10000, cwd: workDir });
34
39
  const childContent = child.toString().trim();
35
40
 
36
41
  expect(childContent).toMatchSnapshot();
37
42
  });
38
43
 
39
44
  it('should generate a graph with specified route and extension ', async () => {
40
- const child = childProcess.execSync(`${command} generate graph -p http://example.com/ -e .xxx`, { cwd: workDir });
45
+ const child = childProcess.execSync(`${command} generate graph -p http://example.com/ -e .xxx`, {
46
+ timeout: 10000,
47
+ cwd: workDir
48
+ });
41
49
  const childContent = child.toString().trim();
42
50
 
43
51
  expect(childContent).toMatchSnapshot();
@@ -1,13 +1,13 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
4
- import * as path from 'path';
5
2
  import * as fs from 'fs';
6
3
  import * as os from 'os';
4
+ import * as path from 'path';
5
+ /* eslint-disable no-sync */
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
7
 
8
8
  describe('Init an ADR Repository', () => {
9
9
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
10
+ const command = `npx tsx ${adr}`;
11
11
 
12
12
  let adrDirectory: string;
13
13
  let workDir: string;
@@ -15,16 +15,20 @@ describe('Init an ADR Repository', () => {
15
15
  beforeEach(() => {
16
16
  // @ts-ignore
17
17
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
18
+ workDir = path.resolve(fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'))));
19
19
  adrDirectory = path.join(workDir, 'doc/adr');
20
20
  });
21
21
 
22
22
  afterEach(() => {
23
- childProcess.execSync(`rm -rf ${workDir}`);
23
+ fs.rmdirSync(workDir, {
24
+ recursive: true,
25
+ maxRetries: 3,
26
+ retryDelay: 500
27
+ });
24
28
  });
25
29
 
26
30
  it('should use the default directory', () => {
27
- childProcess.execSync(`${command} init`, { cwd: workDir });
31
+ childProcess.execSync(`${command} init`, { timeout: 10000, cwd: workDir });
28
32
  const expectedFile: string = path.join(adrDirectory, '0001-record-architecture-decisions.md');
29
33
  const expectedLockFile: string = path.join(adrDirectory, '.adr-sequence.lock');
30
34
  expect(fs.existsSync(expectedFile)).toBeTruthy();
@@ -38,7 +42,7 @@ describe('Init an ADR Repository', () => {
38
42
 
39
43
  it('should use an alternate directory', () => {
40
44
  const directory: string = path.resolve(path.join(workDir, 'tmp', 'alternative-dir'));
41
- childProcess.execSync(`${command} init ${directory}`, { cwd: workDir });
45
+ childProcess.execSync(`${command} init ${directory}`, { timeout: 10000, cwd: workDir });
42
46
 
43
47
  const expectedInitFile: string = path.join(directory, '0001-record-architecture-decisions.md');
44
48
  const expectedLockFile: string = path.join(directory, '.adr-sequence.lock');
@@ -1,13 +1,14 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach, vi } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
8
 
8
9
  describe('Linking Adrs', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
 
12
13
  let adrDirectory: string;
13
14
  let workDir: string;
@@ -15,19 +16,25 @@ describe('Linking Adrs', () => {
15
16
  beforeEach(async () => {
16
17
  // @ts-ignore
17
18
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
19
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
19
20
  adrDirectory = path.join(workDir, 'doc/adr');
20
21
  });
21
22
 
22
23
  afterEach(() => {
23
24
  vi.clearAllMocks();
24
- childProcess.execSync(`rm -rf ${workDir}`);
25
+ rmdirSync(workDir, {
26
+ recursive: true,
27
+ maxRetries: 3,
28
+ retryDelay: 500
29
+ });
25
30
  });
26
31
 
27
32
  it('should link adrs as expected with adr new', async () => {
28
- childProcess.execSync(`${command} new First Record`, { cwd: workDir });
29
- childProcess.execSync(`${command} new Second Record`, { cwd: workDir });
30
- childProcess.execSync(`${command} new -q -l "1:Amends:Amended by" -l "2:Clarifies:Clarified by" Third Record`, { cwd: workDir });
33
+ childProcess.execSync(`${command} new First Record`, { timeout: 10000, cwd: workDir });
34
+ childProcess.execSync(`${command} new Second Record`, { timeout: 10000, cwd: workDir });
35
+ childProcess.execSync(`${command} new -q -l "1:Amends:Amended by" -l "2:Clarifies:Clarified by" Third Record`, {
36
+ cwd: workDir
37
+ });
31
38
 
32
39
  const first: string = path.join(adrDirectory, '0001-first-record.md');
33
40
  const second: string = path.join(adrDirectory, '0002-second-record.md');
@@ -43,11 +50,11 @@ describe('Linking Adrs', () => {
43
50
  });
44
51
 
45
52
  it('should link adrs as expected with adr link', async () => {
46
- childProcess.execSync(`${command} new First Record`, { cwd: workDir });
47
- childProcess.execSync(`${command} new Second Record`, { cwd: workDir });
48
- childProcess.execSync(`${command} new Third Record`, { cwd: workDir });
49
- childProcess.execSync(`${command} link 3 Amends 1 "Amended by"`, { cwd: workDir });
50
- childProcess.execSync(`${command} link 3 Clarifies 2 "Clarified by"`, { cwd: workDir });
53
+ childProcess.execSync(`${command} new First Record`, { timeout: 10000, cwd: workDir });
54
+ childProcess.execSync(`${command} new Second Record`, { timeout: 10000, cwd: workDir });
55
+ childProcess.execSync(`${command} new Third Record`, { timeout: 10000, cwd: workDir });
56
+ childProcess.execSync(`${command} link 3 Amends 1 "Amended by"`, { timeout: 10000, cwd: workDir });
57
+ childProcess.execSync(`${command} link 3 Clarifies 2 "Clarified by"`, { timeout: 10000, cwd: workDir });
51
58
 
52
59
  const first: string = path.join(adrDirectory, '0001-first-record.md');
53
60
  const second: string = path.join(adrDirectory, '0002-second-record.md');
@@ -1,48 +1,53 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
2
+ import { realpathSync, rmdirSync } from 'node:fs';
3
+ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import * as fs from 'fs/promises';
6
- import * as os from 'os';
6
+ /* eslint-disable no-sync */
7
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
8
 
8
9
  describe('Listing', () => {
9
10
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
11
+ const command = `npx tsx ${adr}`;
11
12
 
12
13
  let adrDirectory: string;
13
14
  let workDir: string;
14
15
 
15
16
  beforeEach(async () => {
16
- workDir = await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'));
17
- adrDirectory = path.join(workDir, 'doc/adr');
18
- childProcess.execSync(`${command} init ${adrDirectory}`, { cwd: workDir });
17
+ workDir = path.resolve(realpathSync(await fs.mkdtemp(path.join(os.tmpdir(), 'adr-'))));
18
+ adrDirectory = 'doc/adr';
19
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
19
20
  });
20
21
 
21
22
  afterEach(() => {
22
- childProcess.execSync(`rm -rf ${workDir}`);
23
+ rmdirSync(workDir, {
24
+ recursive: true,
25
+ maxRetries: 3,
26
+ retryDelay: 500
27
+ });
23
28
  });
24
29
 
25
30
  it('should list an empty directory', async () => {
26
- const child = childProcess.execSync(`${command} list`, { cwd: workDir });
31
+ const child = childProcess.execSync(`${command} list`, { timeout: 10000, cwd: workDir });
27
32
  const output = child.toString().trim();
28
33
  expect(output).toEqual('doc/adr/0001-record-architecture-decisions.md');
29
34
  });
30
35
 
31
36
  it('should list when there is an additional one', async () => {
32
- childProcess.execSync(`${command} new first`, { cwd: workDir });
33
- const child = childProcess.execSync(`${command} list`, { cwd: workDir });
37
+ childProcess.execSync(`${command} new first`, { timeout: 10000, cwd: workDir });
38
+ const child = childProcess.execSync(`${command} list`, { timeout: 10000, cwd: workDir });
34
39
  const output = child.toString().trim();
35
40
  expect(output).toEqual('doc/adr/0001-record-architecture-decisions.md\ndoc/adr/0002-first.md');
36
41
  });
37
42
 
38
43
  it('should list when there are more', async () => {
39
- childProcess.execSync(`${command} new first`, { cwd: workDir });
40
- childProcess.execSync(`${command} new second`, { cwd: workDir });
41
- childProcess.execSync(`${command} new third`, { cwd: workDir });
42
- const child = childProcess.execSync(`${command} list`, { cwd: workDir });
44
+ childProcess.execSync(`${command} new first`, { timeout: 10000, cwd: workDir });
45
+ childProcess.execSync(`${command} new second`, { timeout: 10000, cwd: workDir });
46
+ childProcess.execSync(`${command} new third`, { timeout: 10000, cwd: workDir });
47
+ const child = childProcess.execSync(`${command} list`, { timeout: 10000, cwd: workDir });
43
48
  const output = child.toString().trim();
44
- expect(output).toEqual('doc/adr/0001-record-architecture-decisions.md\ndoc/adr/0002-first.md\ndoc/adr/0003-second.md\ndoc/adr/0004-third.md');
49
+ expect(output).toEqual(
50
+ 'doc/adr/0001-record-architecture-decisions.md\ndoc/adr/0002-first.md\ndoc/adr/0003-second.md\ndoc/adr/0004-third.md'
51
+ );
45
52
  });
46
-
47
53
  });
48
-
@@ -1,13 +1,13 @@
1
- /* eslint-disable no-sync */
2
- import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
1
  import * as childProcess from 'child_process';
4
- import * as path from 'path';
5
2
  import * as fs from 'fs';
6
3
  import * as os from 'os';
4
+ import * as path from 'path';
5
+ /* eslint-disable no-sync */
6
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
7
 
8
8
  describe('New Adrs', () => {
9
9
  const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
- const command = `npx ts-node ${adr}`;
10
+ const command = `npx tsx ${adr}`;
11
11
 
12
12
  let adrDirectory: string;
13
13
  let workDir: string;
@@ -15,17 +15,21 @@ describe('New Adrs', () => {
15
15
  beforeEach(() => {
16
16
  // @ts-ignore
17
17
  process.env.ADR_DATE = '1992-01-12';
18
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
18
+ workDir = path.resolve(fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'))));
19
19
  adrDirectory = path.join(workDir, 'doc/adr');
20
20
  });
21
21
 
22
22
  afterEach(() => {
23
- childProcess.execSync(`rm -rf ${workDir}`);
23
+ fs.rmdirSync(workDir, {
24
+ recursive: true,
25
+ maxRetries: 3,
26
+ retryDelay: 500
27
+ });
24
28
  });
25
29
 
26
30
  it('should create a new one normally', () => {
27
- childProcess.execSync(`${command} init ${adrDirectory}`, { cwd: workDir });
28
- childProcess.execSync(`${command} new Example ADR`, { cwd: workDir });
31
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
32
+ childProcess.execSync(`${command} new Example ADR`, { timeout: 10000, cwd: workDir });
29
33
 
30
34
  const expectedNewFile: string = path.join(adrDirectory, '0002-example-adr.md');
31
35
  expect(fs.existsSync(expectedNewFile)).toBeTruthy();
@@ -35,7 +39,7 @@ describe('New Adrs', () => {
35
39
  });
36
40
 
37
41
  it('should create a new one even if no config exists', () => {
38
- childProcess.execSync(`${command} new Example ADR`, { cwd: workDir });
42
+ childProcess.execSync(`${command} new Example ADR`, { timeout: 10000, cwd: workDir });
39
43
 
40
44
  const expectedNewFile: string = path.join(adrDirectory, '0001-example-adr.md');
41
45
  expect(fs.existsSync(expectedNewFile)).toBeTruthy();
@@ -45,8 +49,8 @@ describe('New Adrs', () => {
45
49
  });
46
50
 
47
51
  it('should create a table of contents upon creation', () => {
48
- childProcess.execSync(`${command} init ${adrDirectory}`, { cwd: workDir });
49
- childProcess.execSync(`${command} new Example ADR`, { cwd: workDir });
52
+ childProcess.execSync(`${command} init ${adrDirectory}`, { timeout: 10000, cwd: workDir });
53
+ childProcess.execSync(`${command} new Example ADR`, { timeout: 10000, cwd: workDir });
50
54
 
51
55
  const expectedNewFile: string = path.join(adrDirectory, 'decisions.md');
52
56
  expect(fs.existsSync(expectedNewFile)).toBeTruthy();
@@ -54,5 +58,4 @@ describe('New Adrs', () => {
54
58
  const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
55
59
  expect(fileContents).toMatchSnapshot();
56
60
  });
57
-
58
61
  });