-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
1 parent
c03f0a5
commit df0cfd6
Showing
22 changed files
with
216 additions
and
1 deletion.
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
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
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,14 @@ | ||
{ | ||
"name": "example-workspace", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest run && vitest run --root ./report-test --config vitest.config.report.ts" | ||
}, | ||
"devDependencies": { | ||
"typescript": "latest", | ||
"vite": "^3", | ||
"vitest": "latest", | ||
"vitest-sonar-reporter": "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,8 @@ | ||
{ | ||
"name": "example-workspace-client", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest run" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/example-workspace/packages/client/src/render-user.ts
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,12 @@ | ||
import { parseName } from '@shared'; | ||
|
||
export function renderUser(userName: string) { | ||
const { first, last } = parseName(userName); | ||
|
||
return ` | ||
<div class="user"> | ||
<span class="firstname">${first}</span> | ||
<span class="lastname">${last}</span> | ||
</div> | ||
`; | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/example-workspace/packages/client/test/render-user.test.ts
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,16 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
|
||
import { renderUser } from '../src/render-user'; | ||
|
||
describe('renderUser', () => { | ||
test('renders user', () => { | ||
expect(renderUser('John Doe')).toMatchInlineSnapshot(` | ||
" | ||
<div class=\\"user\\"> | ||
<span class=\\"firstname\\">John</span> | ||
<span class=\\"lastname\\">Doe</span> | ||
</div> | ||
" | ||
`); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
examples/example-workspace/packages/client/vitest.config.ts
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 @@ | ||
import { fileURLToPath } from 'url'; | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
name: 'client', | ||
alias: { | ||
'@shared': fileURLToPath( | ||
new URL('../shared/src/index.ts', import.meta.url) | ||
), | ||
}, | ||
}, | ||
}); |
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,8 @@ | ||
{ | ||
"name": "example-workspace-server", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest run" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
examples/example-workspace/packages/server/src/request-parse.ts
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,8 @@ | ||
import { parseName } from '@shared'; | ||
|
||
export function parseUserFromRequest(request: { | ||
headers: Record<string, string>; | ||
}) { | ||
const header = request.headers['x-user']; | ||
return parseName(header); | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/example-workspace/packages/server/test/request-parse.test.ts
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,14 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { parseUserFromRequest } from '../src/request-parse'; | ||
|
||
describe('parseUserFromRequest', () => { | ||
test('returns user from request', () => { | ||
const request = { headers: { 'x-user': 'John Doe' } }; | ||
|
||
expect(parseUserFromRequest(request)).toEqual({ | ||
first: 'John', | ||
last: 'Doe', | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
examples/example-workspace/packages/server/vitest.config.ts
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 @@ | ||
import { fileURLToPath } from 'url'; | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
name: 'server', | ||
alias: { | ||
'@shared': fileURLToPath( | ||
new URL('../shared/src/index.ts', import.meta.url) | ||
), | ||
}, | ||
}, | ||
}); |
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,8 @@ | ||
{ | ||
"name": "example-workspace-shared", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest run" | ||
} | ||
} |
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 @@ | ||
export * from './user-utils'; |
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,9 @@ | ||
export function parseName(fullname: string) { | ||
const [first, last] = fullname.split(' '); | ||
return { first, last }; | ||
} | ||
|
||
export function getInitials(fullname: string) { | ||
const { first, last } = parseName(fullname); | ||
return `${first[0]}.${last[0]}`; | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/example-workspace/packages/shared/test/user-utils.test.ts
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,19 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { parseName, getInitials } from '../src/user-utils'; | ||
|
||
describe('parseName', () => { | ||
test('returns first name', () => { | ||
expect(parseName('John Doe')).toHaveProperty('first', 'John'); | ||
}); | ||
|
||
test('returns last name', () => { | ||
expect(parseName('John Doe')).toHaveProperty('last', 'Doe'); | ||
}); | ||
}); | ||
|
||
describe('getInitials', () => { | ||
test('returns initials', () => { | ||
expect(getInitials('John Doe')).toBe('J.D'); | ||
}); | ||
}); |
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,7 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
name: 'shared', | ||
}, | ||
}); |
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 @@ | ||
packages: | ||
- packages/* |
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,29 @@ | ||
import { existsSync, readFileSync } from 'node:fs'; | ||
import { expect, test } from 'vitest'; | ||
|
||
import { stabilizeReport } from '../../../test/utils'; | ||
|
||
test('report exists', () => { | ||
expect(existsSync('./sonar-report.xml')).toBe(true); | ||
}); | ||
|
||
test('report matches snapshot', () => { | ||
const output = readFileSync('./sonar-report.xml', 'utf8'); | ||
const report = stabilizeReport(output); | ||
|
||
expect(report).toMatchInlineSnapshot(` | ||
"<testExecutions version=\\"1\\"> | ||
<file path=\\"packages/client/test/render-user.test.ts\\"> | ||
<testCase name=\\"renderUser - renders user\\" duration=\\"123\\" /> | ||
</file> | ||
<file path=\\"packages/server/test/request-parse.test.ts\\"> | ||
<testCase name=\\"parseUserFromRequest - returns user from request\\" duration=\\"123\\" /> | ||
</file> | ||
<file path=\\"packages/shared/test/user-utils.test.ts\\"> | ||
<testCase name=\\"parseName - returns first name\\" duration=\\"123\\" /> | ||
<testCase name=\\"parseName - returns last name\\" duration=\\"123\\" /> | ||
<testCase name=\\"getInitials - returns initials\\" duration=\\"123\\" /> | ||
</file> | ||
</testExecutions>" | ||
`); | ||
}); |
8 changes: 8 additions & 0 deletions
8
examples/example-workspace/report-test/vitest.config.report.ts
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,8 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['report.test.ts'], | ||
reporters: ['verbose'], | ||
}, | ||
}); |
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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"@shared": ["./packages/shared/src/index.ts"] | ||
} | ||
} | ||
} |
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,10 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
reporters: ['default', 'vitest-sonar-reporter'], | ||
outputFile: { | ||
'vitest-sonar-reporter': './sonar-report.xml', | ||
}, | ||
}, | ||
}); |
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 @@ | ||
import { defineWorkspace } from 'vitest/config'; | ||
|
||
export default defineWorkspace(['packages/*']); |