| 34 | } |
| 35 | |
| 36 | async execute() { |
| 37 | if (!this.args.watch) { |
| 38 | this.bundler.on('bundle-error', () => process.exit(1)); |
| 39 | if (!this.args.inspect) { |
| 40 | this.testHost.workerHost.on('worker-error', () => process.exit(1)); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | const siteInitialized = this.site ? this.site.init() : Promise.resolve(); |
| 45 | |
| 46 | await Promise.all([ |
| 47 | this.bundler.bundle(), |
| 48 | this.testHost.start(), |
| 49 | siteInitialized, |
| 50 | this.kv.init() |
| 51 | ]); |
| 52 | |
| 53 | const failures = await this.testHost.runTests( |
| 54 | this.bundler.code, |
| 55 | this.site ? this.site.manifest : null |
| 56 | ); |
| 57 | |
| 58 | if (this.args.watch) { |
| 59 | const update = () => |
| 60 | this.testHost.runTests( |
| 61 | this.bundler.code, |
| 62 | this.site ? this.site.manifest : null |
| 63 | ); |
| 64 | this.bundler.on('bundle-end', update); |
| 65 | if (this.site) { |
| 66 | this.site.on('change', update); |
| 67 | } |
| 68 | } else { |
| 69 | this.dispose(); |
| 70 | process.exit(failures ? 1 : 0); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | dispose() { |
| 75 | this.bundler.dispose(); |