Skip to content

Commit

Permalink
fix: clean before test
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed May 21, 2024
1 parent 8f94fdb commit 1a3aeaa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dev:web": "pnpm --filter @notesuite/client dev & pnpm --filter @notesuite/common dev",
"dev:server": "pnpm --filter @notesuite/server start",
"dev:client": "pnpm --filter @notesuite/client tauri dev & pnpm --filter @notesuite/common dev",
"test": "playwright test --debug",
"test:clean": "pnpm clean && pnpm test",
"test": "playwright test",
"test:headed": "playwright test --debug",
"clean": "pnpm --filter @notesuite/server clean"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function initWSServer(context: AppContext) {

wss.on('connection', (ws, request) => {
setupWSConnection(ws, request, { gc: true });
console.log('doc count', [...docs.keys()].length);
// console.log('doc count', [...docs.keys()].length);
});

const { activeWorkspaceId } = context.db.data;
Expand Down
7 changes: 7 additions & 0 deletions tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test.describe('basic test', () => {
webPort: 5173,
backendPort: 3000,
};
let workspaceId = '';
test.beforeAll(() => agent.start(options));

test('local server works', async ({ page }) => {
Expand All @@ -21,6 +22,12 @@ test.describe('basic test', () => {
await page.getByPlaceholder('Workspace name').fill('hello');
await page.getByRole('button', { name: 'Create' }).click();
await expect(page.getByText('Test Client')).toBeVisible();

const currentUrl = page.url();
const parts = currentUrl.split('/');
const id = parts[parts.length - 1];
expect(id).not.toBe('');
workspaceId = id;
});

test.afterAll(() => agent.stop());
Expand Down
1 change: 1 addition & 0 deletions tests/common/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TestAgent {

async start(options: StartOptions) {
this.options = options;
await this.runner.clean();
await Promise.all([
this.runner.startServer(options.backendPort, options.name),
this.runner.startWeb(options.webPort, options.backendPort),
Expand Down
18 changes: 18 additions & 0 deletions tests/common/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ export class AppRunner {
this.webProcess = null;
}

async clean() {
await /** @type {Promise<void>} */ (
new Promise((resolve, reject) => {
const process = spawn('pnpm', ['clean'], {
stdio: 'inherit',
});

process.on('error', err => reject(err));
process.on('close', code => {
if (code !== 0) {
reject(new Error(`Clean process exited with code ${code}`));
}
resolve();
});
})
);
}

/**
* @param {number} port
* @param {string} instanceName
Expand Down

0 comments on commit 1a3aeaa

Please sign in to comment.