* Launches a Percy agent instance. * * @return {!Promise } percy agent instance.
()
| 146 | * @return {!Promise<Percy|undefined>} percy agent instance. |
| 147 | */ |
| 148 | async function launchPercyAgent() { |
| 149 | if (argv.percy_disabled) { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | const {default: PercyModule} = await PercyModulePromise; |
| 154 | const percy = await PercyModule.start({ |
| 155 | token: process.env.PERCY_TOKEN, |
| 156 | loglevel: argv.percy_agent_debug ? 'debug' : 'info', |
| 157 | port: PERCY_AGENT_PORT, |
| 158 | config: path.join(__dirname, '.percy.yaml'), |
| 159 | discovery: { |
| 160 | launchOptions: { |
| 161 | executable: locateChromeExecutablePath(), |
| 162 | }, |
| 163 | }, |
| 164 | }); |
| 165 | |
| 166 | await new Promise((resolve, reject) => { |
| 167 | const percyIsEnabledTimeout = setTimeout(() => { |
| 168 | log('fatal', 'Percy agent is unreachable after', WAIT_FOR_AGENT_MS, 'ms'); |
| 169 | reject(false); |
| 170 | }, WAIT_FOR_AGENT_MS); |
| 171 | |
| 172 | while (true) { |
| 173 | try { |
| 174 | if (isPercyEnabled()) { |
| 175 | clearTimeout(percyIsEnabledTimeout); |
| 176 | log( |
| 177 | 'info', |
| 178 | 'Percy agent is enabled and reachable on port', |
| 179 | PERCY_AGENT_PORT |
| 180 | ); |
| 181 | return resolve(true); |
| 182 | } |
| 183 | } catch { |
| 184 | // Ignore transient errors. Promise will reject after WAIT_FOR_AGENT_MS. |
| 185 | } |
| 186 | } |
| 187 | }); |
| 188 | |
| 189 | if (process.env['PERCY_TARGET_COMMIT']) { |
| 190 | log( |
| 191 | 'info', |
| 192 | 'The Percy build is baselined on top of commit', |
| 193 | cyan(shortSha(process.env['PERCY_TARGET_COMMIT'])) |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | return percy; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Adds a test error and logs it if running locally (not as part of CI). |
no test coverage detected