Changeset View
Changeset View
Standalone View
Standalone View
cypress/plugins/index.js
/** | /** | ||||
* Copyright (C) 2019-2022 The Software Heritage developers | * Copyright (C) 2019-2022 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
const axios = require('axios'); | const axios = require('axios'); | ||||
const {execFileSync} = require('child_process'); | const {execFileSync} = require('child_process'); | ||||
const fs = require('fs'); | // const fs = require('fs'); | ||||
const sqlite3 = require('sqlite3').verbose(); | const sqlite3 = require('sqlite3').verbose(); | ||||
let buildId = process.env.CYPRESS_PARALLEL_BUILD_ID; | let buildId = process.env.CYPRESS_PARALLEL_BUILD_ID; | ||||
if (buildId === undefined) { | if (buildId === undefined) { | ||||
buildId = ''; | buildId = ''; | ||||
} | } | ||||
async function httpGet(url) { | async function httpGet(url) { | ||||
Show All 18 Lines | return { | ||||
'revision': lastOriginHeadRevision.id, | 'revision': lastOriginHeadRevision.id, | ||||
'snapshot': lastOriginSnapshot.id | 'snapshot': lastOriginSnapshot.id | ||||
}; | }; | ||||
}; | }; | ||||
function getDatabase() { | function getDatabase() { | ||||
const db = new sqlite3.Database(`./swh-web-test${buildId}.sqlite3`); | const db = new sqlite3.Database(`./swh-web-test${buildId}.sqlite3`); | ||||
// to prevent "database is locked" error when running tests | // to prevent "database is locked" error when running tests | ||||
db.configure('busyTimeout', 20000); | |||||
db.run('PRAGMA journal_mode = WAL;'); | db.run('PRAGMA journal_mode = WAL;'); | ||||
return db; | return db; | ||||
} | } | ||||
module.exports = (on, config) => { | module.exports = (on, config) => { | ||||
require('@cypress/code-coverage/task')(on, config); | require('@cypress/code-coverage/task')(on, config); | ||||
// produce JSON files prior launching browser in order to dynamically generate tests | // produce JSON files prior launching browser in order to dynamically generate tests | ||||
on('before:browser:launch', function(browser, launchOptions) { | on('before:browser:launch', function(browser, launchOptions) { | ||||
return new Promise((resolve) => { | if (browser.name === 'electron') { | ||||
const p1 = axios.get(`${config.baseUrl}/tests/data/content/code/extensions/`); | launchOptions.preferences.webPreferences.additionalArguments = ['--enable-logging=stderr', '--v=1']; | ||||
const p2 = axios.get(`${config.baseUrl}/tests/data/content/code/filenames/`); | } | ||||
Promise.all([p1, p2]) | return launchOptions; | ||||
.then(function(responses) { | |||||
fs.writeFileSync('cypress/fixtures/source-file-extensions.json', JSON.stringify(responses[0].data)); | |||||
fs.writeFileSync('cypress/fixtures/source-file-names.json', JSON.stringify(responses[1].data)); | |||||
resolve(); | |||||
}); | |||||
}); | |||||
}); | }); | ||||
on('task', { | on('task', { | ||||
getSwhTestsData: async() => { | getSwhTestsData: async() => { | ||||
if (!global.swhTestsData) { | if (!global.swhTestsData) { | ||||
const swhTestsData = {}; | const swhTestsData = {}; | ||||
swhTestsData.unarchivedRepo = { | swhTestsData.unarchivedRepo = { | ||||
url: 'https://github.com/SoftwareHeritage/swh-web', | url: 'https://github.com/SoftwareHeritage/swh-web', | ||||
type: 'git', | type: 'git', | ||||
▲ Show 20 Lines • Show All 114 Lines • Show Last 20 Lines |