Skip to content

Commit

Permalink
feat: update unit&e2e test case
Browse files Browse the repository at this point in the history
  • Loading branch information
laclys committed Jun 17, 2023
1 parent 297d10b commit d4d9f4d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions e2e/playground/basic/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hello World
4 changes: 2 additions & 2 deletions e2e/playground/basic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const siteUrl = 'http://localhost:5173'

test('Verify that the page renders properly', async ({ page }) => {
await page.goto(siteUrl)

await page.waitForLoadState('networkidle') // 保证所有网络请求都得到相应
const res = await page.evaluate(async () => {
const pageContent = document.body.innerText
return pageContent.includes('This is Layout Component')
return pageContent.includes('Hello')
})
expect(res).toBe(true)
})
17 changes: 16 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ pnpm i

npm link

# de/compiler
# compiler
pnpm run start

# test:unit
pnpm test:unit

# test:e2e
pnpm test:e2e

# usage
## dev
shaco dev [dir]
Expand All @@ -22,4 +28,13 @@ shaco build [dir]

```
![](demo.jpg)

---
unit test ✅
![](./test-passed/unit.png)

e2e test ✅

![](./test-passed/e2e.png)

Have fun!
2 changes: 2 additions & 0 deletions src/node/__test__/md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ describe('Markdown compile cases', async () => {
\\"depth\\": 4
}
];
export const title = 'h1 lac';
"
`)
})
Expand Down
6 changes: 3 additions & 3 deletions src/node/plugin-routes/RouteService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ describe('RouteService', async () => {
.toMatchInlineSnapshot(`
"
import React from 'react';
import loadable from '@loadable/component';
import loadable from \\"@loadable/component\\";
const Route0 = loadable(() => import('TEST_DIR/a.mdx'));
const Route1 = loadable(() => import('TEST_DIR/guide/index.mdx'));
export const routes = [
{ path: '/a', element: React.createElement(Route0) },
{ path: '/guide/', element: React.createElement(Route1) }
{ path: '/a', element: React.createElement(Route0), preload: () => import('TEST_DIR/a.mdx') },
{ path: '/guide/', element: React.createElement(Route1), preload: () => import('TEST_DIR/guide/index.mdx') }
];
"
`)
Expand Down
7 changes: 5 additions & 2 deletions src/node/plugin/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { relative, join } from 'path'
import sirv from 'sirv'
import { SiteConfig } from 'shared/types/index'
import { PACKAGE_ROOT } from 'node/constants'
import fs from 'fs-extra'

const SITE_DATA_ID = 'shaco:site-data'

Expand Down Expand Up @@ -54,8 +55,10 @@ export function pluginConfig(
},
configureServer(server) {
const publicDir = join(config.root, 'public')
// sirv: https://github.com/lukeed/sirv(An optimized middleware & CLI application for serving static files~!)
server.middlewares.use(sirv(publicDir))
if (fs.existsSync(publicDir)) {
// sirv: https://github.com/lukeed/sirv(An optimized middleware & CLI application for serving static files~!)
server.middlewares.use(sirv(publicDir))
}
}
}
}
Binary file added test-passed/e2e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test-passed/unit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default defineConfig({
test: {
environment: 'node',
passWithNoTests: true,
exclude: ['**/node_modules/**', '**/dist/**'],
exclude: ['**/node_modules/**', '**/dist/**', '**/e2e/**'],
threads: true
}
})

0 comments on commit d4d9f4d

Please sign in to comment.