Skip to content

Commit

Permalink
chore(eslint): update version and lint typescript
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Jan 11, 2023
1 parent e470048 commit fcc576c
Show file tree
Hide file tree
Showing 10 changed files with 596 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cypress/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = {
extends: [
'plugin:cypress/recommended',
],
};
}
87 changes: 49 additions & 38 deletions cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* eslint-disable no-console */
import type { Stream } from 'stream'
import type { Container } from 'dockerode'

import Docker from 'dockerode'
import waitOn from 'wait-on'
import path from 'path'
import waitOn from 'wait-on'

export const docker = new Docker()
import pkg from '../package.json'

const pkg = require('../package.json');
const APP_PATH = path.resolve(__dirname, '../')
const APP_NAME = pkg.name

const CONTAINER_NAME = 'nextcloud-cypress-tests-' + APP_NAME
const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server'

export const docker = new Docker()

/**
* Start the testing container
*
* @param branch the current git branch
*/
export const startNextcloud = async function (branch: string = 'master'): Promise<any> {
export const startNextcloud = async function(branch = 'master'): Promise<string> {
try {
// Pulling images
console.log('Pulling images... ⏳')
await new Promise((resolve, reject): any => docker.pull(SERVER_IMAGE, (err, stream) => {
// https://github.com/apocas/dockerode/issues/357
docker.modem.followProgress(stream, onFinished)
function onFinished(err, output) {
await new Promise((resolve, reject) => docker.pull(SERVER_IMAGE, (_err, stream: Stream) => {
const onFinished = function(err: Error | null) {
if (!err) {
resolve(true)
return
return resolve(true)
}
reject(err)
}
// https://github.com/apocas/dockerode/issues/357
docker.modem.followProgress(stream, onFinished)
}))
console.log(`└─ Done`)
console.log('└─ Done')

// Getting latest image
console.log('\nChecking running containers... 🔍')
Expand All @@ -62,22 +67,22 @@ export const startNextcloud = async function (branch: string = 'master'): Promis
const oldContainer = docker.getContainer(CONTAINER_NAME)
const oldContainerData = await oldContainer.inspect()
if (oldContainerData.State.Running) {
console.log(`├─ Existing running container found`)
console.log('├─ Existing running container found')
if (localImage[0].Id !== oldContainerData.Image) {
console.log(`└─ But running container is outdated, replacing...`)
console.log('└─ But running container is outdated, replacing...')
} else {
// Get container's IP
console.log(`├─ Reusing that container`)
let ip = await getContainerIP(oldContainer)
console.log('├─ Reusing that container')
const ip = await getContainerIP(oldContainer)
return ip
}
} else {
console.log(`└─ None found!`)
console.log('└─ None found!')
}
// Forcing any remnants to be removed just in case
await oldContainer.remove({ force: true })
} catch (error) {
console.log(`└─ None found!`)
console.log('└─ None found!')
}

// Starting container
Expand All @@ -92,17 +97,17 @@ export const startNextcloud = async function (branch: string = 'master'): Promis
},
Env: [
`BRANCH=${branch}`,
]
],
})
await container.start()

// Get container's IP
let ip = await getContainerIP(container)
const ip = await getContainerIP(container)

console.log(`├─ Nextcloud container's IP is ${ip} 🌏`)
return ip
} catch (err) {
console.log(`└─ Unable to start the container 🛑`)
console.log('└─ Unable to start the container 🛑')
console.log(err)
stopNextcloud()
throw new Error('Unable to start the container')
Expand All @@ -112,7 +117,7 @@ export const startNextcloud = async function (branch: string = 'master'): Promis
/**
* Configure Nextcloud
*/
export const configureNextcloud = async function () {
export const configureNextcloud = async function() {
console.log('\nConfiguring nextcloud...')
const container = docker.getContainer(CONTAINER_NAME)
await runExec(container, ['php', 'occ', '--version'], true)
Expand All @@ -132,9 +137,9 @@ export const configureNextcloud = async function () {
}

/**
* Force stop the testing container
* Force stop the testing nextcloud container
*/
export const stopNextcloud = async function () {
export const stopNextcloud = async function() {
try {
const container = docker.getContainer(CONTAINER_NAME)
console.log('Stopping Nextcloud container...')
Expand All @@ -146,17 +151,19 @@ export const stopNextcloud = async function () {
}

/**
* Get the testing container's IP
* Get the testing container's IP address
*
* @param container the container to get the ip from
*/
export const getContainerIP = async function (
container = docker.getContainer(CONTAINER_NAME)
export const getContainerIP = async function(
container: Container = docker.getContainer(CONTAINER_NAME)
): Promise<string> {
let ip = ''
let tries = 0
while (ip === '' && tries < 10) {
tries++

await container.inspect(function (err, data) {
await container.inspect(function(_err, data) {
ip = data?.NetworkSettings?.IPAddress || ''
})

Expand All @@ -170,21 +177,25 @@ export const getContainerIP = async function (
return ip
}

// Would be simpler to start the container from cypress.config.ts,
// but when checking out different branches, it can take a few seconds
// Until we can properly configure the baseUrl retry intervals,
// We need to make sure the server is already running before cypress
// https://github.com/cypress-io/cypress/issues/22676
export const waitOnNextcloud = async function (ip: string) {
/**
* Would be simpler to start the container from cypress.config.ts,
* but when checking out different branches, it can take a few seconds
* Until we can properly configure the baseUrl retry intervals,
* We need to make sure the server is already running before cypress
*
* @param {string} ip the ip to wait for
* @see https://github.com/cypress-io/cypress/issues/22676
*/
export const waitOnNextcloud = async function(ip: string) {
console.log('├─ Waiting for Nextcloud to be ready... ⏳')
await waitOn({ resources: [`http://${ip}/index.php`] })
console.log('└─ Done')
}

const runExec = async function (
const runExec = async function(
container: Docker.Container,
command: string[],
verbose: boolean = false
verbose = false
) {
const exec = await container.exec({
Cmd: command,
Expand All @@ -193,8 +204,8 @@ const runExec = async function (
User: 'www-data',
})

return new Promise((resolve, reject) => {
exec.start({}, (err, stream) => {
return new Promise((resolve) => {
exec.start({}, (_err, stream) => {
if (stream) {
stream.setEncoding('utf-8')
stream.on('data', str => {
Expand All @@ -208,6 +219,6 @@ const runExec = async function (
})
}

const sleep = function (milliseconds: number) {
const sleep = function(milliseconds: number) {
return new Promise((resolve) => setTimeout(resolve, milliseconds))
}
4 changes: 2 additions & 2 deletions cypress/e2e/images/images-custom-list-loadmore.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Open custom list of images in viewer with pagination', function() {
.should('contain', 'image4.jpg')
})

it('Open the viewer with a specific list', async function() {
it('Open the viewer with a specific list', function() {
// make sure we only loadMore once
let loaded = false

Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Open custom list of images in viewer with pagination', function() {
etag: 'etag456',
},
]
}
},
})
})
})
Expand Down
15 changes: 15 additions & 0 deletions cypress/e2e/mixins/oddname.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Cypress.on('fail', (error, runnable) => {
throw error // throw error to have test still fail
})

/**
*
* @param file
* @param type
* @param sidebar
*/
export default function(file, type, sidebar = false) {
const placedName = naughtyFileName(file)

Expand Down Expand Up @@ -79,13 +85,19 @@ export default function(file, type, sidebar = false) {
cy.openFile(folderName)
})

/**
*
*/
function noLoadingAnimation() {
cy.get('body > .viewer', { timeout: 10000 })
.should('be.visible')
.and('have.class', 'modal-mask')
.and('not.have.class', 'icon-loading')
}

/**
*
*/
function menuOk() {
cy.get('body > .viewer .icon-error').should('not.exist')
cy.get('body > .viewer .modal-title').should('contain', placedName)
Expand All @@ -94,6 +106,9 @@ export default function(file, type, sidebar = false) {
)
}

/**
*
*/
function arrowsOK() {
cy.get('body > .viewer button.prev').should('not.be.visible')
cy.get('body > .viewer button.next').should('not.be.visible')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/videos/video.webm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ import videoTest from '../mixins/video.js'

describe('Open video.webm in viewer', function() {
videoTest('video.webm', 'video/webm')
})
})
1 change: 1 addition & 0 deletions cypress/e2e/visual-regression.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('Visual regression tests ', function() {
video.get(0).currentTime = 1
})
// wait a bit for things to be settled
// eslint-disable-next-line
cy.wait(250)
cy.compareSnapshot('video', 0.02)
})
Expand Down
5 changes: 3 additions & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { addCommands, User } from '@nextcloud/cypress'
import { basename } from 'path'
import axios from '@nextcloud/axios'
import compareSnapshotCommand from 'cypress-visual-regression/dist/command'
import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js'

addCommands()
compareSnapshotCommand()
Expand Down Expand Up @@ -96,6 +96,7 @@ Cypress.Commands.add('createFolder', (user, target) => {

Cypress.Commands.add('openFile', fileName => {
cy.get(`.files-fileList tr[data-file="${CSS.escape(fileName)}"] a.name`).click()
// eslint-disable-next-line
cy.wait(250)
})

Expand All @@ -113,7 +114,7 @@ Cypress.Commands.add('deleteFile', fileName => {
* Create a share link and return the share url
*
* @param {string} path the file/folder path
* @returns {string} the share link url
* @return {string} the share link url
*/
Cypress.Commands.add('createLinkShare', path => {
return cy.window().then(async window => {
Expand Down
5 changes: 1 addition & 4 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
import './commands.js'
Loading

0 comments on commit fcc576c

Please sign in to comment.