Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud-libraries/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Lint eslint

on: pull_request

permissions:
contents: read

concurrency:
group: lint-eslint-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: eslint

steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Read package.json
uses: nextcloud-libraries/parse-package-engines-action@122ae05d4257008180a514e1ddeb0c1b9d094bdd # v0.1.0
id: versions

- name: Set up node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ steps.versions.outputs.node-version }}

- name: Set up npm
run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'

- name: Install dependencies
env:
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true
run: npm ci

- name: Lint
run: npm run lint
3 changes: 2 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

// Making sure we're forcing the development mode
process.env.NODE_ENV = 'development'
process.env.npm_package_name = 'nextcloud-e2e-test-server'

import { configureNextcloud, createSnapshot, setupUsers, startNextcloud, stopNextcloud, waitOnNextcloud } from './lib/docker'
import { defineConfig } from 'cypress'
import vitePreprocessor from 'cypress-vite'
import { configureNextcloud, createSnapshot, setupUsers, startNextcloud, stopNextcloud, waitOnNextcloud } from './lib/docker.ts'

export default defineConfig({
projectId: 'h2z7r3',
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/docker.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

describe('Run command', function() {

it('yields the output as stdout', function() {
cy.runCommand('ls')
.its('stdout')
Expand All @@ -17,5 +16,4 @@ describe('Run command', function() {
.should('contain', 'DATA')
.should('contain', 'Hello')
})

})
11 changes: 6 additions & 5 deletions cypress/e2e/sessions.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { User } from '../../dist/cypress'

import { User } from '../../lib/cypress.ts'

describe('Login and logout', function() {
it('Login and see the default files list', function() {
Expand All @@ -15,7 +16,7 @@ describe('Login and logout', function() {
cy.visit('/apps/files')
cy.url().should('include', '/apps/files')

cy.window().then(window => {
cy.window().then((window) => {
expect((window as any).OC?.currentUser).to.eq(user.userId)
})
})
Expand All @@ -26,7 +27,7 @@ describe('Login and logout', function() {
cy.visit('/apps/files')
cy.url().should('include', '/apps/files')

cy.window().then(window => {
cy.window().then((window) => {
expect((window as any).OC?.currentUser).to.eq('test1')
})

Expand All @@ -43,7 +44,7 @@ describe('Login and logout', function() {
cy.visit('/apps/files')
cy.url().should('include', '/apps/files')

cy.window().then(window => {
cy.window().then((window) => {
expect((window as any).OC?.currentUser).to.eq(user.userId)
})
})
Expand Down
13 changes: 7 additions & 6 deletions cypress/e2e/snapshots.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { User } from '../../dist/cypress'
import { randHash } from '../utils'

import { User } from '../../lib/cypress.ts'
import { randHash } from '../utils/index.ts'

describe('Create a snapshot and a user', function() {
let snapshot: string

it('Create a snapshot', function() {
cy.saveState().then(_snapshot => {
cy.saveState().then((_snapshot) => {
snapshot = _snapshot
})
})
Expand All @@ -24,7 +25,7 @@ describe('Create a snapshot and a user', function() {
cy.visit('/apps/files')
cy.url().should('include', '/apps/files')

cy.listUsers().then(users => {
cy.listUsers().then((users) => {
expect(users).to.contain(user.userId)
})
})
Expand All @@ -37,7 +38,7 @@ describe('Create a snapshot and a user', function() {
cy.visit('/apps/files')
cy.url().should('include', '/login')

cy.listUsers().then(users => {
cy.listUsers().then((users) => {
expect(users).to.not.contain(user.userId)
})
})
Expand Down
35 changes: 18 additions & 17 deletions cypress/e2e/users.cy.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { User } from '../../dist/cypress'
import { randHash } from '../utils'

import { User } from '../../lib/cypress.ts'
import { randHash } from '../utils/index.ts'

describe('Create user and login', function() {
it('Create random user and log in', function() {
cy.createRandomUser().then(user => {
cy.createRandomUser().then((user) => {
cy.login(user)
})

Expand All @@ -28,7 +29,7 @@ describe('Create user and login', function() {

it('Fail creating an existing user', function() {
const user = new User('admin', 'password')
cy.createUser(user).then(response => {
cy.createUser(user).then((response) => {
cy.wrap(response).its('status').should('eq', 400)
cy.wrap(response).its('body.ocs.meta.message').should('eq', 'User already exists')
})
Expand All @@ -41,13 +42,13 @@ describe('List users and delete user', () => {
const user = new User(hash, 'password')
cy.createUser(user).then(() => {
cy.login(user)
cy.listUsers().then(users => {
cy.listUsers().then((users) => {
expect(users).to.contain(user.userId)
})
})

cy.deleteUser(user).then(() => {
cy.listUsers().then(users => {
cy.listUsers().then((users) => {
expect(users).to.not.contain(user.userId)
})
})
Expand All @@ -72,7 +73,7 @@ describe('Write and read user metadata', () => {
})

cy.modifyUser(user, 'displayname', 'John Doe')
cy.getUserData(user).then(response => {
cy.getUserData(user).then((response) => {
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(response.body, 'text/xml')
expect(xmlDoc.querySelector('data displayname')?.textContent).to.eq('John Doe')
Expand All @@ -82,34 +83,34 @@ describe('Write and read user metadata', () => {

describe('Enable and disable users', () => {
const hash = 'user' + randHash()
let user = new User(hash, 'password')
const user = new User(hash, 'password')

beforeEach(() => cy.createUser(user))
afterEach(() => cy.deleteUser(user))

it('can disable user', () => {
cy.listUsers(true).then(details => {
const usersDetails = details.filter(v => v.id === user.userId)
cy.listUsers(true).then((details) => {
const usersDetails = details.filter((v) => v.id === user.userId)
expect(usersDetails.length).to.eq(1)
expect(usersDetails[0].enabled).to.eq('1')
})

cy.enableUser(user, false).listUsers(true).then(details => {
const usersDetails = details.filter(v => v.id === user.userId)
cy.enableUser(user, false).listUsers(true).then((details) => {
const usersDetails = details.filter((v) => v.id === user.userId)
expect(usersDetails.length).to.eq(1)
expect(usersDetails[0].enabled).to.eq('')
})
})

it('can enable a user', () => {
cy.enableUser(user, false).listUsers(true).then(details => {
const usersDetails = details.filter(v => v.id === user.userId)
cy.enableUser(user, false).listUsers(true).then((details) => {
const usersDetails = details.filter((v) => v.id === user.userId)
expect(usersDetails.length).to.eq(1)
expect(usersDetails[0].enabled).to.eq('')
})

cy.enableUser(user).listUsers(true).then(details => {
const usersDetails = details.filter(v => v.id === user.userId)
cy.enableUser(user).listUsers(true).then((details) => {
const usersDetails = details.filter((v) => v.id === user.userId)
expect(usersDetails.length).to.eq(1)
expect(usersDetails[0].enabled).to.eq('1')
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
// ***********************************************
//

import { addCommands } from '../../dist/cypress'
import { addCommands } from '../../lib/cypress.ts'
addCommands()
2 changes: 1 addition & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
// https://on.cypress.io/configuration
// ***********************************************************

import './commands'
import './commands.ts'
35 changes: 35 additions & 0 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { recommendedLibrary } from '@nextcloud/eslint-config'
import { defineConfig } from 'eslint/config'
import globals from 'globals'

export default defineConfig([
...recommendedLibrary,

{
name: 'playwright-overrides',
files: ['playwright/**/*.ts'],
rules: {
// required for fixtures
'no-empty-pattern': 'off',
},
},

{
name: 'node-scripts',
files: ['lib/docker.ts', 'playwright/**/*.mjs'],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
// Node-side tooling where progress output to the console is intentional
'no-console': 'off',
},
},
])
1 change: 0 additions & 1 deletion lib/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ export class User {
return new User(uid)
}
}

9 changes: 8 additions & 1 deletion lib/commands/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

import { basename } from '@nextcloud/paths'

/**
*
*/
function getContainerName(): Cypress.Chainable<string> {
return cy.exec('pwd').then(({ stdout }) => {
const name = basename(stdout).replace(' ', '')
return cy.wrap(`nextcloud-e2e-test-server_${name}`)
})
}

/**
*
* @param command

Check warning on line 20 in lib/commands/docker.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc @param "command" description
* @param options

Check warning on line 21 in lib/commands/docker.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc @param "options" description
*/
export function runCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec> {
const env = Object.entries(options?.env ?? {})
.map(([name, value]) => `-e '${name}=${value}'`)
Expand All @@ -22,5 +30,4 @@
// Wrapping command inside bash -c "..." to allow using '*'.
return cy.exec(`docker exec --user www-data --workdir /var/www/html ${env} ${containerName} bash -c "${command}"`, options)
})

}
12 changes: 8 additions & 4 deletions lib/commands/getNc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Selector } from "../selectors/index.ts"
import type { Selector } from '../selectors/index.ts'

export const getNc = function(selector: Selector, args: Object = {}): Cypress.Chainable<JQuery<HTMLElement>> {
/**
*
* @param selector

Check warning on line 10 in lib/commands/getNc.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc @param "selector" description
* @param args

Check warning on line 11 in lib/commands/getNc.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing JSDoc @param "args" description
*/
export function getNc(selector: Selector, args: object = {}): Cypress.Chainable<JQuery<HTMLElement>> {
if (typeof selector !== 'function') {
console.error(selector)
throw new Error('Invalid selector')
throw new Error(`Invalid selector: ${String(selector)}`)
}
return selector(args)
}
12 changes: 6 additions & 6 deletions lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

export * from './getNc'
export * from './sessions'
export * from './users'
export * from './state'
export * from './docker'
export * from './occ'
export * from './getNc.ts'
export * from './sessions.ts'
export * from './users.ts'
export * from './state.ts'
export * from './docker.ts'
export * from './occ.ts'
Loading
Loading