|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import assert from 'node:assert'; |
| 8 | +import fs from 'node:fs'; |
| 9 | +import os from 'node:os'; |
| 10 | +import path from 'node:path'; |
| 11 | +import {describe, it, afterEach, beforeEach} from 'node:test'; |
| 12 | + |
| 13 | +import { |
| 14 | + assertDaemonIsNotRunning, |
| 15 | + assertDaemonIsRunning, |
| 16 | + runCli, |
| 17 | +} from '../utils.js'; |
| 18 | + |
| 19 | +describe('chrome-devtools', () => { |
| 20 | + beforeEach(async () => { |
| 21 | + await runCli(['stop']); |
| 22 | + await assertDaemonIsNotRunning(); |
| 23 | + }); |
| 24 | + |
| 25 | + afterEach(async () => { |
| 26 | + await runCli(['stop']); |
| 27 | + await assertDaemonIsNotRunning(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('can start and stop the daemon', async () => { |
| 31 | + await assertDaemonIsNotRunning(); |
| 32 | + |
| 33 | + const startResult = await runCli(['start']); |
| 34 | + assert.strictEqual( |
| 35 | + startResult.status, |
| 36 | + 0, |
| 37 | + `start command failed: ${startResult.stderr}`, |
| 38 | + ); |
| 39 | + |
| 40 | + await assertDaemonIsRunning(); |
| 41 | + |
| 42 | + const stopResult = await runCli(['stop']); |
| 43 | + assert.strictEqual( |
| 44 | + stopResult.status, |
| 45 | + 0, |
| 46 | + `stop command failed: ${stopResult.stderr}`, |
| 47 | + ); |
| 48 | + |
| 49 | + await assertDaemonIsNotRunning(); |
| 50 | + }); |
| 51 | + |
| 52 | + it('can start the daemon with userDataDir', async () => { |
| 53 | + const userDataDir = path.join( |
| 54 | + os.tmpdir(), |
| 55 | + `chrome-devtools-test-${crypto.randomUUID()}`, |
| 56 | + ); |
| 57 | + fs.mkdirSync(userDataDir, {recursive: true}); |
| 58 | + |
| 59 | + const startResult = await runCli(['start', '--userDataDir', userDataDir]); |
| 60 | + assert.strictEqual( |
| 61 | + startResult.status, |
| 62 | + 0, |
| 63 | + `start command failed: ${startResult.stderr}`, |
| 64 | + ); |
| 65 | + assert.ok( |
| 66 | + !startResult.stderr.includes( |
| 67 | + 'Arguments userDataDir and isolated are mutually exclusive', |
| 68 | + ), |
| 69 | + `unexpected conflict error: ${startResult.stderr}`, |
| 70 | + ); |
| 71 | + |
| 72 | + await assertDaemonIsRunning(); |
| 73 | + }); |
| 74 | +}); |
0 commit comments