@meza/adr-tools 1.0.1

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 (51) hide show
  1. package/.adr-dir +1 -0
  2. package/.editorconfig +13 -0
  3. package/.eslintignore +2 -0
  4. package/.eslintrc.json +23 -0
  5. package/.github/dependabot.yml +14 -0
  6. package/.github/stale.yml +18 -0
  7. package/.github/workflows/auto-merge.yml +14 -0
  8. package/.github/workflows/ci.yml +89 -0
  9. package/.husky/commit-msg +4 -0
  10. package/.releaserc.json +41 -0
  11. package/README.md +30 -0
  12. package/doc/adr/0001-record-architecture-decisions.md +21 -0
  13. package/doc/adr/0002-using-heavy-e2e-tests.md +20 -0
  14. package/docs/CHANGELOG.md +6 -0
  15. package/package.json +91 -0
  16. package/src/environment.d.ts +14 -0
  17. package/src/index.ts +115 -0
  18. package/src/lib/adr.ts +242 -0
  19. package/src/lib/config.ts +34 -0
  20. package/src/lib/links.test.ts +86 -0
  21. package/src/lib/links.ts +34 -0
  22. package/src/lib/manipulator.test.ts +88 -0
  23. package/src/lib/manipulator.ts +86 -0
  24. package/src/lib/numbering.test.ts +41 -0
  25. package/src/lib/numbering.ts +26 -0
  26. package/src/lib/template.ts +18 -0
  27. package/src/templates/init.md +21 -0
  28. package/src/templates/template.md +19 -0
  29. package/src/version.ts +1 -0
  30. package/tests/__snapshots__/generate-graph.e2e.test.ts.snap +39 -0
  31. package/tests/__snapshots__/init-adr-repository.e2e.test.ts.snap +51 -0
  32. package/tests/__snapshots__/linking-records.e2e.test.ts.snap +155 -0
  33. package/tests/__snapshots__/new-adr.e2e.test.ts.snap +54 -0
  34. package/tests/__snapshots__/superseding-records.e2e.test.ts.snap +122 -0
  35. package/tests/__snapshots__/toc-prefixing.e2e.test.ts.snap +9 -0
  36. package/tests/__snapshots__/use-template-override.e2e.test.ts.snap +17 -0
  37. package/tests/edit-on-create.e2e.test.ts +54 -0
  38. package/tests/fake-editor +3 -0
  39. package/tests/fake-visual +3 -0
  40. package/tests/funny-characters.e2e.test.ts +43 -0
  41. package/tests/generate-graph.e2e.test.ts +45 -0
  42. package/tests/init-adr-repository.e2e.test.ts +53 -0
  43. package/tests/linking-records.e2e.test.ts +64 -0
  44. package/tests/list-adrs.e2e.test.ts +48 -0
  45. package/tests/new-adr.e2e.test.ts +58 -0
  46. package/tests/superseding-records.e2e.test.ts +58 -0
  47. package/tests/toc-prefixing.e2e.test.ts +38 -0
  48. package/tests/use-template-override.e2e.test.ts +43 -0
  49. package/tests/work-form-other-directories.e2e.test.ts +44 -0
  50. package/tsconfig.json +22 -0
  51. package/vitest.config.ts +12 -0
@@ -0,0 +1,19 @@
1
+ # NUMBER. TITLE
2
+
3
+ Date: DATE
4
+
5
+ ## Status
6
+
7
+ STATUS
8
+
9
+ ## Context
10
+
11
+ The issue motivating this decision, and any context that influences or constrains the decision.
12
+
13
+ ## Decision
14
+
15
+ The change that we're proposing or have agreed to implement.
16
+
17
+ ## Consequences
18
+
19
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const LIB_VERSION = '0.0.0';
@@ -0,0 +1,39 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Generating Graphs > should generate a graph 1`] = `
4
+ "digraph {
5
+ node [shape=plaintext];
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];
16
+ }
17
+ _3 -> _2 [label=\\"Supersedes\\", weight=0]
18
+ _5 -> _3 [label=\\"Supersedes\\", weight=0]
19
+ }"
20
+ `;
21
+
22
+ exports[`Generating Graphs > should generate a graph with specified route and extension 1`] = `
23
+ "digraph {
24
+ node [shape=plaintext];
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];
35
+ }
36
+ _3 -> _2 [label=\\"Supersedes\\", weight=0]
37
+ _5 -> _3 [label=\\"Supersedes\\", weight=0]
38
+ }"
39
+ `;
@@ -0,0 +1,51 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Init an ADR Repository > should use an alternate directory 1`] = `
4
+ "# 1. Record architecture decisions
5
+
6
+ Date: 1992-01-12
7
+
8
+ ## Status
9
+
10
+ Accepted
11
+
12
+ ## Context
13
+
14
+ We need to record the architectural decisions made on this project.
15
+
16
+ ## Decision
17
+
18
+ We will use Architecture Decision Records, as [described by Michael Nygard](https://cognitect.com/blog/2011/11/15/documenting-architecture-decisions).
19
+
20
+ ## Consequences
21
+
22
+ See Michael Nygard's article, linked above.
23
+ For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
24
+ > For a node version of the same tooling, see Meza's [adr-tools](https://github.com/meza/adr-tools).
25
+ "
26
+ `;
27
+
28
+ exports[`Init an ADR Repository > should use the default directory 1`] = `
29
+ "# 1. Record architecture decisions
30
+
31
+ Date: 1992-01-12
32
+
33
+ ## Status
34
+
35
+ Accepted
36
+
37
+ ## Context
38
+
39
+ We need to record the architectural decisions made on this project.
40
+
41
+ ## Decision
42
+
43
+ We will use Architecture Decision Records, as [described by Michael Nygard](https://cognitect.com/blog/2011/11/15/documenting-architecture-decisions).
44
+
45
+ ## Consequences
46
+
47
+ See Michael Nygard's article, linked above.
48
+ For a lightweight ADR toolset, see Nat Pryce's [adr-tools](https://github.com/npryce/adr-tools).
49
+ > For a node version of the same tooling, see Meza's [adr-tools](https://github.com/meza/adr-tools).
50
+ "
51
+ `;
@@ -0,0 +1,155 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Linking Adrs > should link adrs as expected with adr link 1`] = `
4
+ "# 1. First Record
5
+
6
+ Date: 1992-01-12
7
+
8
+ ## Status
9
+
10
+ Accepted
11
+
12
+ Amended by [3. Third Record](0003-third-record.md)
13
+
14
+ ## Context
15
+
16
+ The issue motivating this decision, and any context that influences or constrains the decision.
17
+
18
+ ## Decision
19
+
20
+ The change that we're proposing or have agreed to implement.
21
+
22
+ ## Consequences
23
+
24
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
25
+ "
26
+ `;
27
+
28
+ exports[`Linking Adrs > should link adrs as expected with adr link 2`] = `
29
+ "# 2. Second Record
30
+
31
+ Date: 1992-01-12
32
+
33
+ ## Status
34
+
35
+ Accepted
36
+
37
+ Clarified by [3. Third Record](0003-third-record.md)
38
+
39
+ ## Context
40
+
41
+ The issue motivating this decision, and any context that influences or constrains the decision.
42
+
43
+ ## Decision
44
+
45
+ The change that we're proposing or have agreed to implement.
46
+
47
+ ## Consequences
48
+
49
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
50
+ "
51
+ `;
52
+
53
+ exports[`Linking Adrs > should link adrs as expected with adr link 3`] = `
54
+ "# 3. Third Record
55
+
56
+ Date: 1992-01-12
57
+
58
+ ## Status
59
+
60
+ Accepted
61
+
62
+ Amends [1. First Record](0001-first-record.md)
63
+
64
+ Clarifies [2. Second Record](0002-second-record.md)
65
+
66
+ ## Context
67
+
68
+ The issue motivating this decision, and any context that influences or constrains the decision.
69
+
70
+ ## Decision
71
+
72
+ The change that we're proposing or have agreed to implement.
73
+
74
+ ## Consequences
75
+
76
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
77
+ "
78
+ `;
79
+
80
+ exports[`Linking Adrs > should link adrs as expected with adr new 1`] = `
81
+ "# 1. First Record
82
+
83
+ Date: 1992-01-12
84
+
85
+ ## Status
86
+
87
+ Accepted
88
+
89
+ Amended by [3. Third Record](0003-third-record.md)
90
+
91
+ ## Context
92
+
93
+ The issue motivating this decision, and any context that influences or constrains the decision.
94
+
95
+ ## Decision
96
+
97
+ The change that we're proposing or have agreed to implement.
98
+
99
+ ## Consequences
100
+
101
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
102
+ "
103
+ `;
104
+
105
+ exports[`Linking Adrs > should link adrs as expected with adr new 2`] = `
106
+ "# 2. Second Record
107
+
108
+ Date: 1992-01-12
109
+
110
+ ## Status
111
+
112
+ Accepted
113
+
114
+ Clarified by [3. Third Record](0003-third-record.md)
115
+
116
+ ## Context
117
+
118
+ The issue motivating this decision, and any context that influences or constrains the decision.
119
+
120
+ ## Decision
121
+
122
+ The change that we're proposing or have agreed to implement.
123
+
124
+ ## Consequences
125
+
126
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
127
+ "
128
+ `;
129
+
130
+ exports[`Linking Adrs > should link adrs as expected with adr new 3`] = `
131
+ "# 3. Third Record
132
+
133
+ Date: 1992-01-12
134
+
135
+ ## Status
136
+
137
+ Accepted
138
+
139
+ Amends [1. First Record](0001-first-record.md)
140
+
141
+ Clarifies [2. Second Record](0002-second-record.md)
142
+
143
+ ## Context
144
+
145
+ The issue motivating this decision, and any context that influences or constrains the decision.
146
+
147
+ ## Decision
148
+
149
+ The change that we're proposing or have agreed to implement.
150
+
151
+ ## Consequences
152
+
153
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
154
+ "
155
+ `;
@@ -0,0 +1,54 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`New Adrs > should create a new one even if no config exists 1`] = `
4
+ "# 1. Example ADR
5
+
6
+ Date: 1992-01-12
7
+
8
+ ## Status
9
+
10
+ Accepted
11
+
12
+ ## Context
13
+
14
+ The issue motivating this decision, and any context that influences or constrains the decision.
15
+
16
+ ## Decision
17
+
18
+ The change that we're proposing or have agreed to implement.
19
+
20
+ ## Consequences
21
+
22
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
23
+ "
24
+ `;
25
+
26
+ exports[`New Adrs > should create a new one normally 1`] = `
27
+ "# 2. Example ADR
28
+
29
+ Date: 1992-01-12
30
+
31
+ ## Status
32
+
33
+ Accepted
34
+
35
+ ## Context
36
+
37
+ The issue motivating this decision, and any context that influences or constrains the decision.
38
+
39
+ ## Decision
40
+
41
+ The change that we're proposing or have agreed to implement.
42
+
43
+ ## Consequences
44
+
45
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
46
+ "
47
+ `;
48
+
49
+ exports[`New Adrs > should create a table of contents upon creation 1`] = `
50
+ "# Table of Contents
51
+
52
+ [1. Record architecture decisions](0001-record-architecture-decisions.md)
53
+ [2. Example ADR](0002-example-adr.md)"
54
+ `;
@@ -0,0 +1,122 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Superseding Adrs > should be able to supersede multiple records 1`] = `
4
+ "# 1. First Record
5
+
6
+ Date: 1992-01-12
7
+
8
+ ## Status
9
+
10
+ Superseded by [3. Third Record](0003-third-record.md)
11
+
12
+ ## Context
13
+
14
+ The issue motivating this decision, and any context that influences or constrains the decision.
15
+
16
+ ## Decision
17
+
18
+ The change that we're proposing or have agreed to implement.
19
+
20
+ ## Consequences
21
+
22
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
23
+ "
24
+ `;
25
+
26
+ exports[`Superseding Adrs > should be able to supersede multiple records 2`] = `
27
+ "# 2. Second Record
28
+
29
+ Date: 1992-01-12
30
+
31
+ ## Status
32
+
33
+ Superseded by [3. Third Record](0003-third-record.md)
34
+
35
+ ## Context
36
+
37
+ The issue motivating this decision, and any context that influences or constrains the decision.
38
+
39
+ ## Decision
40
+
41
+ The change that we're proposing or have agreed to implement.
42
+
43
+ ## Consequences
44
+
45
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
46
+ "
47
+ `;
48
+
49
+ exports[`Superseding Adrs > should be able to supersede multiple records 3`] = `
50
+ "# 3. Third Record
51
+
52
+ Date: 1992-01-12
53
+
54
+ ## Status
55
+
56
+ Accepted
57
+
58
+ Supersedes [1. First Record](0001-first-record.md)
59
+
60
+ Supersedes [2. Second Record](0002-second-record.md)
61
+
62
+ ## Context
63
+
64
+ The issue motivating this decision, and any context that influences or constrains the decision.
65
+
66
+ ## Decision
67
+
68
+ The change that we're proposing or have agreed to implement.
69
+
70
+ ## Consequences
71
+
72
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
73
+ "
74
+ `;
75
+
76
+ exports[`Superseding Adrs > should be able to supersede previous adrs 1`] = `
77
+ "# 1. First Record
78
+
79
+ Date: 1992-01-12
80
+
81
+ ## Status
82
+
83
+ Superseded by [2. Second Record](0002-second-record.md)
84
+
85
+ ## Context
86
+
87
+ The issue motivating this decision, and any context that influences or constrains the decision.
88
+
89
+ ## Decision
90
+
91
+ The change that we're proposing or have agreed to implement.
92
+
93
+ ## Consequences
94
+
95
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
96
+ "
97
+ `;
98
+
99
+ exports[`Superseding Adrs > should be able to supersede previous adrs 2`] = `
100
+ "# 2. Second Record
101
+
102
+ Date: 1992-01-12
103
+
104
+ ## Status
105
+
106
+ Accepted
107
+
108
+ Supersedes [1. First Record](0001-first-record.md)
109
+
110
+ ## Context
111
+
112
+ The issue motivating this decision, and any context that influences or constrains the decision.
113
+
114
+ ## Decision
115
+
116
+ The change that we're proposing or have agreed to implement.
117
+
118
+ ## Consequences
119
+
120
+ What becomes easier or more difficult to do and any risks introduced by the change that will need to be mitigated.
121
+ "
122
+ `;
@@ -0,0 +1,9 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Generating TOC > should add a path prefix to the toc when there is one supplied 1`] = `
4
+ "# Table of Contents
5
+
6
+ [1. First Record](foo/doc/adr/0001-first-record.md)
7
+ [2. Second Record](foo/doc/adr/0002-second-record.md)
8
+ [3. Third Record](foo/doc/adr/0003-third-record.md)"
9
+ `;
@@ -0,0 +1,17 @@
1
+ // Vitest Snapshot v1
2
+
3
+ exports[`Overriding templates > should use an override template if one exists 1`] = `
4
+ "# This is an override template
5
+ Example ADR
6
+ 1992-01-12
7
+ 2
8
+ Accepted"
9
+ `;
10
+
11
+ exports[`Overriding templates > should use an override template if one exists 2`] = `
12
+ "# This is an override template
13
+ Another Example ADR
14
+ 1992-01-12
15
+ 3
16
+ Accepted"
17
+ `;
@@ -0,0 +1,54 @@
1
+ /* eslint-disable no-sync */
2
+ import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
+ import * as childProcess from 'child_process';
4
+ import * as path from 'path';
5
+ import * as fs from 'fs';
6
+ import * as os from 'os';
7
+
8
+ describe('Edit new Adrs on creation', () => {
9
+ const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
+ const command = `npx ts-node ${adr}`;
11
+ const visualHelper = path.resolve(path.dirname(__filename), './fake-visual');
12
+ const editorHelper = path.resolve(path.dirname(__filename), './fake-editor');
13
+
14
+ let adrDirectory: string;
15
+ let workDir: string;
16
+
17
+ beforeEach(() => {
18
+ // @ts-ignore
19
+ process.env.ADR_DATE = '1992-01-12';
20
+ workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
21
+ adrDirectory = path.join(workDir, 'doc/adr');
22
+ });
23
+
24
+ afterEach(() => {
25
+ childProcess.execSync(`rm -rf ${workDir}`);
26
+ });
27
+
28
+ it('should open a new ADR in the VISUAL', () => {
29
+ childProcess.execSync(`VISUAL="${visualHelper}" ${command} new Example ADR`, { cwd: workDir });
30
+
31
+ const expectedNewFile: string = path.join(workDir, 'visual.out');
32
+ const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
33
+ expect(fileContents.trim()).toEqual(`VISUAL ${adrDirectory}/0001-example-adr.md`);
34
+ });
35
+
36
+ it('should open a new ADR in the EDITOR', () => {
37
+ childProcess.execSync(`EDITOR="${editorHelper}" ${command} new Example ADR`, { cwd: workDir });
38
+
39
+ const expectedNewFile: string = path.join(workDir, 'editor.out');
40
+ const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
41
+ expect(fileContents.trim()).toEqual(`EDITOR ${adrDirectory}/0001-example-adr.md`);
42
+ });
43
+
44
+ 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 });
46
+
47
+ expect(fs.existsSync(path.join(workDir, 'editor.out'))).toBeFalsy();
48
+
49
+ const expectedNewFile: string = path.join(workDir, 'visual.out');
50
+ const fileContents = fs.readFileSync(expectedNewFile, 'utf8');
51
+ expect(fileContents.trim()).toEqual(`VISUAL ${adrDirectory}/0001-example-adr.md`);
52
+ });
53
+
54
+ });
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ echo EDITOR "$@" > editor.out
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ echo VISUAL "$@" > visual.out
@@ -0,0 +1,43 @@
1
+ /* 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();
13
+ let adrDirectory: string;
14
+
15
+ afterEach(() => {
16
+ childProcess.execSync(`rm -rf .adr-dir doc tmp ${randomDir}`, { cwd: workDir });
17
+ });
18
+
19
+ beforeEach(() => {
20
+ randomDir = uuidv4();
21
+ adrDirectory = path.resolve(path.join(workDir, randomDir));
22
+ childProcess.execSync(`${command} init ${randomDir}`, { cwd: workDir });
23
+ });
24
+
25
+ it('should handle titles with periods in them', async () => {
26
+ childProcess.execSync(`${command} new Something About Node.JS`, { cwd: workDir });
27
+ const expectedFile: string = path.join(adrDirectory, '0002-something-about-node-js.md');
28
+ expect(fs.existsSync(expectedFile)).toBeTruthy();
29
+ });
30
+
31
+ it('should handle titles with slashes in them', async () => {
32
+ childProcess.execSync(`${command} new Slash/Slash/Slash/`, { cwd: workDir });
33
+ const expectedFile: string = path.join(adrDirectory, '0002-slash-slash-slash.md');
34
+ expect(fs.existsSync(expectedFile)).toBeTruthy();
35
+ });
36
+
37
+ it('should handle titles with other weirdness in them', async () => {
38
+ childProcess.execSync(`${command} new -- "-Bar-"`, { cwd: workDir });
39
+ const expectedFile: string = path.join(adrDirectory, '0002-bar.md');
40
+ expect(fs.existsSync(expectedFile)).toBeTruthy();
41
+ });
42
+ });
43
+
@@ -0,0 +1,45 @@
1
+ /* eslint-disable no-sync */
2
+ import { describe, it, expect, afterAll, beforeAll, vi, afterEach } from 'vitest';
3
+ import * as childProcess from 'child_process';
4
+ import * as path from 'path';
5
+ import * as fs from 'fs/promises';
6
+ import * as os from 'os';
7
+
8
+ describe('Generating Graphs', () => {
9
+ const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
+ const command = `npx ts-node ${adr}`;
11
+ let workDir: string;
12
+
13
+ beforeAll(async () => {
14
+ // @ts-ignore
15
+ 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 });
22
+ });
23
+
24
+ afterEach(() => {
25
+ vi.clearAllMocks();
26
+ });
27
+
28
+ afterAll(() => {
29
+ childProcess.execSync(`rm -rf ${workDir}`);
30
+ });
31
+
32
+ it('should generate a graph', async () => {
33
+ const child = childProcess.execSync(`${command} generate graph`, { cwd: workDir });
34
+ const childContent = child.toString().trim();
35
+
36
+ expect(childContent).toMatchSnapshot();
37
+ });
38
+
39
+ 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 });
41
+ const childContent = child.toString().trim();
42
+
43
+ expect(childContent).toMatchSnapshot();
44
+ });
45
+ });
@@ -0,0 +1,53 @@
1
+ /* eslint-disable no-sync */
2
+ import { describe, it, expect, afterEach, beforeEach } from 'vitest';
3
+ import * as childProcess from 'child_process';
4
+ import * as path from 'path';
5
+ import * as fs from 'fs';
6
+ import * as os from 'os';
7
+
8
+ describe('Init an ADR Repository', () => {
9
+ const adr = path.resolve(path.dirname(__filename), '../src/index.ts');
10
+ const command = `npx ts-node ${adr}`;
11
+
12
+ let adrDirectory: string;
13
+ let workDir: string;
14
+
15
+ beforeEach(() => {
16
+ // @ts-ignore
17
+ process.env.ADR_DATE = '1992-01-12';
18
+ workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'adr-'));
19
+ adrDirectory = path.join(workDir, 'doc/adr');
20
+ });
21
+
22
+ afterEach(() => {
23
+ childProcess.execSync(`rm -rf ${workDir}`);
24
+ });
25
+
26
+ it('should use the default directory', () => {
27
+ childProcess.execSync(`${command} init`, { cwd: workDir });
28
+ const expectedFile: string = path.join(adrDirectory, '0001-record-architecture-decisions.md');
29
+ const expectedLockFile: string = path.join(adrDirectory, '.adr-sequence.lock');
30
+ expect(fs.existsSync(expectedFile)).toBeTruthy();
31
+ expect(fs.existsSync(expectedLockFile)).toBeTruthy();
32
+
33
+ const fileContents = fs.readFileSync(expectedFile, 'utf8');
34
+ const lockFileContents = fs.readFileSync(expectedLockFile, 'utf8');
35
+ expect(fileContents).toMatchSnapshot();
36
+ expect(lockFileContents).toEqual('1');
37
+ });
38
+
39
+ it('should use an alternate directory', () => {
40
+ const directory: string = path.resolve(path.join(workDir, 'tmp', 'alternative-dir'));
41
+ childProcess.execSync(`${command} init ${directory}`, { cwd: workDir });
42
+
43
+ const expectedInitFile: string = path.join(directory, '0001-record-architecture-decisions.md');
44
+ const expectedLockFile: string = path.join(directory, '.adr-sequence.lock');
45
+ expect(fs.existsSync(expectedInitFile)).toBeTruthy();
46
+ expect(fs.existsSync(expectedLockFile)).toBeTruthy();
47
+
48
+ const fileContents = fs.readFileSync(expectedInitFile, 'utf8');
49
+ const lockFileContents = fs.readFileSync(expectedLockFile, 'utf8');
50
+ expect(fileContents).toMatchSnapshot();
51
+ expect(lockFileContents).toEqual('1');
52
+ });
53
+ });