Skip to content

Commit

Permalink
Test reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
hugihlynsson committed Mar 6, 2024
1 parent 868118f commit 9870fea
Show file tree
Hide file tree
Showing 5 changed files with 669 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
yarn-error.log
cli.js
Avo.js
reporter.js
reporter.js
reporter.test.js
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"lint": "eslint cli.ts",
"format": "prettier --write cli.ts",
"check-format": "prettier --check cli.ts",
"compile": "tsc"
"compile": "tsc",
"test": "tsc && vitest"
},
"files": [
"cli.js",
Expand Down Expand Up @@ -65,6 +66,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.25.2",
"prettier": "3.2.5",
"typescript": "^5.0.2"
"typescript": "^5.0.2",
"vitest": "^1.3.1"
}
}
47 changes: 47 additions & 0 deletions reporter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect, test, vi } from 'vitest'; // eslint-disable-line import/no-extraneous-dependencies
import { tree } from './reporter.js';

test('tree', () => {
const consoleSpy = vi.spyOn(console, 'log');
tree('testing', []);
expect(consoleSpy).toHaveBeenCalledWith('testing\n');

tree('testing', [{ name: 'firstNode' }]);
expect(consoleSpy).toHaveBeenCalledWith(`testing
└─ firstNode
`);

tree('testing', [{ name: 'firstNode', children: [{ name: 'secondNode' }] }]);
expect(consoleSpy).toHaveBeenCalledWith(`testing
└─ firstNode
└─ secondNode
`);

tree('testing', [
{
name: 'firstNode',
children: [{ name: 'secondNode' }, { name: 'thirdNode' }],
},
]);
expect(consoleSpy).toHaveBeenCalledWith(`testing
└─ firstNode
├─ secondNode
└─ thirdNode
`);

tree('testing', [
{
name: 'firstNode',
children: [
{ name: 'secondNode', children: [{ name: 'secondNodeChild' }] },
{ name: 'thirdNode' },
],
},
]);
expect(consoleSpy).toHaveBeenCalledWith(`testing
└─ firstNode
├─ secondNode
│ └─ secondNodeChild
└─ thirdNode
`);
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"strict": false,
"skipLibCheck": true
},
"files": ["cli.ts", "Avo.ts"]
"files": ["cli.ts", "Avo.ts", "reporter.ts", "reporter.test.ts"]
}
Loading

0 comments on commit 9870fea

Please sign in to comment.