1// Copyright (C) 2021 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15const NodeEnvironment = require('jest-environment-node'); 16const puppeteer = require('puppeteer'); 17 18module.exports = class IntegrationtestEnvironment extends NodeEnvironment { 19 constructor(config) { 20 super(config); 21 } 22 23 async setup() { 24 await super.setup(); 25 const headless = process.env.PERFETTO_UI_TESTS_INTERACTIVE !== '1'; 26 if (headless) { 27 console.log('Starting Perfetto UI tests in headless mode.'); 28 console.log( 29 'Pass --interactive to run-integrationtests or set ' + 30 'PERFETTO_UI_TESTS_INTERACTIVE=1 to inspect the behavior ' + 31 'in a visible Chrome window'); 32 } 33 this.global.__BROWSER__ = await puppeteer.launch({ 34 args: [ 35 '--window-size=1920,1080', 36 '--disable-accelerated-2d-canvas', 37 '--disable-gpu', 38 '--no-sandbox', // Disable sandbox to run in Docker. 39 '--disable-setuid-sandbox', 40 '--font-render-hinting=none', 41 '--enable-benchmarking', // Disable finch and other sources of non 42 // determinism. 43 ], 44 45 // This is so screenshot in --interactive and headless mode match. The 46 // scrollbars are never part of the screenshot, but without this cmdline 47 // switch, in headless mode we don't get any blank space (as if it was 48 // overflow:hidden) and that changes the layout of the page. 49 ignoreDefaultArgs: ['--hide-scrollbars'], 50 51 headless: headless, 52 }); 53 } 54 55 async teardown() { 56 if (this.global.__BROWSER__) { 57 await this.global.__BROWSER__.close(); 58 } 59 await super.teardown(); 60 } 61 62 runScript(script) { 63 return super.runScript(script); 64 } 65}; 66