Skip to content

Commit 89652f2

Browse files
max-nextcloudsusnux
authored andcommitted
feat!: Export docker functions from main entry
Signed-off-by: Max <max@nextcloud.com>
1 parent 9ca167f commit 89652f2

9 files changed

Lines changed: 186 additions & 155 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Please take a look at the [forms app](https://github.com/nextcloud/forms) for an
3434
You can use the `cypress` folder and the `cypress.config.ts` in this repository as starting points or adjust your `cypress.config.ts` (or `.js`):
3535

3636
```js
37-
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/cypress/docker'
37+
import { configureNextcloud, startNextcloud, stopNextcloud, waitOnNextcloud } from '@nextcloud/e2e-test-server'
3838

3939
export default defineConfig({
4040
// ...
@@ -72,16 +72,16 @@ You can find [the list of all available commands here](https://nextcloud.github.
7272

7373
```js
7474
// cypress/support/commands.js
75-
import { addCommands } from '@nextcloud/cypress'
75+
import { addCommands } from '@nextcloud/e2e-test-server/cypress'
7676

7777
addCommands()
7878
```
7979

8080
```js
8181
// cypress/support/commands.js
82-
import { getNc } from '@nextcloud/cypress/commands'
82+
import { login } from '@nextcloud/e2e-test-server/commands'
8383

84-
Cypress.Commands.add('getNc', getNc)
84+
Cypress.Commands.add('login', login)
8585
```
8686

8787
## Selectors (:warn: deprecated)

cypress/support/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
// ***********************************************
1515
//
1616

17-
import { addCommands } from '../../dist/'
17+
import { addCommands } from '../../dist/cypress'
1818
addCommands()

lib/User.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
export class User {
7+
userId: string
8+
password: string
9+
language: string
10+
11+
constructor(user: string, password: string = user, language = 'en') {
12+
this.userId = user
13+
this.password = password
14+
this.language = language
15+
}
16+
}
17+

lib/commands/sessions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { User } from "./users"
6+
import type { User } from "../User"
77

88
/**
99
* You should always upload files and/or create users

lib/commands/users.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
export class User {
7-
userId: string
8-
password: string
9-
language: string
10-
11-
constructor(user: string, password: string = user, language = 'en') {
12-
this.userId = user
13-
this.password = password
14-
this.language = language
15-
}
16-
}
6+
import { User } from "../User"
177

188
export const randHash = () => Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 10)
199

@@ -40,8 +30,8 @@ export const createUser = function(user: User): Cypress.Chainable<Cypress.Respon
4030
return cy.request({
4131
method: 'POST',
4232
url,
43-
body: {
44-
userid: user.userId,
33+
body: {
34+
userid: user.userId,
4535
password: user.password
4636
},
4737
auth: {
@@ -168,7 +158,7 @@ export const modifyUser = function(user: User, key: string, value: any): Cypress
168158

169159
/**
170160
* Query metadata for and in behalf of a given user
171-
*
161+
*
172162
* @param user User to change
173163
*/
174164
export const getUserData = function(user: User): Cypress.Chainable<Cypress.Response<any>> {

lib/cypress.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import { User } from "./User"
6+
import { getNc, restoreState, runCommand, runOccCommand, saveState } from "./commands"
7+
import { login, logout } from "./commands/sessions"
8+
import { createRandomUser, createUser, deleteUser, modifyUser, listUsers, getUserData, enableUser } from "./commands/users"
9+
import type { Selector } from "./selectors"
10+
11+
declare global {
12+
namespace Cypress {
13+
interface Chainable {
14+
/**
15+
* Get an element from the Nextcloud selector set.
16+
* @example cy.getNc(FileList)
17+
* cy.getNc(FileRow, { id: fileInfo.id })
18+
*/
19+
getNc(selector: Selector, args?: Object): Cypress.Chainable<JQuery<HTMLElement>>
20+
21+
/**
22+
* Login on a Nextcloud instance
23+
*/
24+
login(user: User): void
25+
26+
/**
27+
* Logout from a Nextcloud instance
28+
*/
29+
logout(): void
30+
31+
/**
32+
* Create a random user on the Nextcloud instance
33+
*
34+
* **Warning**: Using this function will reset the previous session
35+
*/
36+
createRandomUser(): Cypress.Chainable<User>
37+
38+
/**
39+
* Create a user on the Nextcloud instance
40+
*
41+
* **Warning**: Using this function will reset the previous session
42+
*/
43+
createUser(user: User): Cypress.Chainable<Cypress.Response<any>>
44+
45+
/**
46+
* Delete a user on the Nextcloud instance
47+
*
48+
* **Warning**: Using this function will reset the previous session
49+
*/
50+
deleteUser(user: User): Cypress.Chainable<Cypress.Response<any>>
51+
52+
/**
53+
* Query list of users on the Nextcloud instance
54+
*
55+
* **Warning**: Using this function will reset the previous session
56+
*
57+
* @param details Set to true to fetch users with detailed information (default false)
58+
* @return List of user IDs or list of Users (if details was set to true)
59+
*/
60+
listUsers<b extends boolean>(details?: b): Cypress.Chainable<b extends true ? Record<string, string>[] : string[]>
61+
listUsers(details?: boolean): Cypress.Chainable<Record<string,string>[] | string[]>
62+
63+
/**
64+
* Modify an attribute of a given user on the Nextcloud instance
65+
*
66+
* @param user User who modifies their metadata
67+
* @param key Attribute name
68+
* @param value New attribute value
69+
*/
70+
modifyUser(user: User, key: string, value: any): Cypress.Chainable<Cypress.Response<any>>
71+
72+
/**
73+
* Enable or disable a given user
74+
*
75+
* @param user user whom to enable or disable
76+
* @param enable True to enable, false to disable (default is enable)
77+
*/
78+
enableUser(user: User, enable?: boolean): Cypress.Chainable<Cypress.Response<any>>
79+
80+
/**
81+
*
82+
* Query metadata for, and in behalf, of a given user
83+
*
84+
* @param user User whom metadata to query
85+
*/
86+
getUserData(user: User): Cypress.Chainable<Cypress.Response<any>>
87+
88+
/**
89+
* Create a snapshot of the current DB and data folder state.
90+
*
91+
* @return string the ID of the snapshot
92+
*/
93+
saveState(): Cypress.Chainable<string>
94+
95+
/**
96+
* Restore a snapshot of the database
97+
* Default is the post-setup state
98+
*
99+
* @param snapshot string the ID of the snapshot
100+
*/
101+
restoreState(snapshot?: string): Cypress.Chainable<void>
102+
103+
/**
104+
* Run a command in the docker container
105+
*
106+
*/
107+
runCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>
108+
109+
/**
110+
* Run an occ command
111+
*/
112+
runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>
113+
}
114+
}
115+
}
116+
117+
/**
118+
* Register all existing commands provided by this library
119+
*
120+
* You can also manually register those commands by importing them
121+
* @example import { login } from '@nextcloud/e2e-test-server/commands'
122+
* Cypress.Commands.add('login', login)
123+
*/
124+
export const addCommands = function() {
125+
Cypress.Commands.add('getNc', getNc)
126+
Cypress.Commands.add('login', login)
127+
Cypress.Commands.add('logout', logout)
128+
Cypress.Commands.add('createRandomUser', createRandomUser)
129+
Cypress.Commands.add('createUser', createUser)
130+
Cypress.Commands.add('deleteUser', deleteUser)
131+
Cypress.Commands.add('listUsers', listUsers)
132+
Cypress.Commands.add('modifyUser', modifyUser)
133+
Cypress.Commands.add('enableUser', enableUser)
134+
Cypress.Commands.add('getUserData', getUserData)
135+
Cypress.Commands.add('saveState', saveState)
136+
Cypress.Commands.add('restoreState', restoreState)
137+
Cypress.Commands.add('runCommand', runCommand)
138+
Cypress.Commands.add('runOccCommand', runOccCommand)
139+
}
140+
141+
export { User }

lib/index.ts

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -2,139 +2,6 @@
22
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
import { getNc, restoreState, runCommand, runOccCommand, saveState } from "./commands"
6-
import { login, logout } from "./commands/sessions"
7-
import { User, createRandomUser, createUser, deleteUser, modifyUser, listUsers, getUserData, enableUser } from "./commands/users"
8-
import type { Selector } from "./selectors"
95

10-
declare global {
11-
namespace Cypress {
12-
interface Chainable {
13-
/**
14-
* Get an element from the Nextcloud selector set.
15-
* @example cy.getNc(FileList)
16-
* cy.getNc(FileRow, { id: fileInfo.id })
17-
*/
18-
getNc(selector: Selector, args?: Object): Cypress.Chainable<JQuery<HTMLElement>>
19-
20-
/**
21-
* Login on a Nextcloud instance
22-
*/
23-
login(user: User): void
24-
25-
/**
26-
* Logout from a Nextcloud instance
27-
*/
28-
logout(): void
29-
30-
/**
31-
* Create a random user on the Nextcloud instance
32-
*
33-
* **Warning**: Using this function will reset the previous session
34-
*/
35-
createRandomUser(): Cypress.Chainable<User>
36-
37-
/**
38-
* Create a user on the Nextcloud instance
39-
*
40-
* **Warning**: Using this function will reset the previous session
41-
*/
42-
createUser(user: User): Cypress.Chainable<Cypress.Response<any>>
43-
44-
/**
45-
* Delete a user on the Nextcloud instance
46-
*
47-
* **Warning**: Using this function will reset the previous session
48-
*/
49-
deleteUser(user: User): Cypress.Chainable<Cypress.Response<any>>
50-
51-
/**
52-
* Query list of users on the Nextcloud instance
53-
*
54-
* **Warning**: Using this function will reset the previous session
55-
*
56-
* @param details Set to true to fetch users with detailed information (default false)
57-
* @return List of user IDs or list of Users (if details was set to true)
58-
*/
59-
listUsers<b extends boolean>(details?: b): Cypress.Chainable<b extends true ? Record<string, string>[] : string[]>
60-
listUsers(details?: boolean): Cypress.Chainable<Record<string,string>[] | string[]>
61-
62-
/**
63-
* Modify an attribute of a given user on the Nextcloud instance
64-
*
65-
* @param user User who modifies their metadata
66-
* @param key Attribute name
67-
* @param value New attribute value
68-
*/
69-
modifyUser(user: User, key: string, value: any): Cypress.Chainable<Cypress.Response<any>>
70-
71-
/**
72-
* Enable or disable a given user
73-
*
74-
* @param user user whom to enable or disable
75-
* @param enable True to enable, false to disable (default is enable)
76-
*/
77-
enableUser(user: User, enable?: boolean): Cypress.Chainable<Cypress.Response<any>>
78-
79-
/**
80-
*
81-
* Query metadata for, and in behalf, of a given user
82-
*
83-
* @param user User whom metadata to query
84-
*/
85-
getUserData(user: User): Cypress.Chainable<Cypress.Response<any>>
86-
87-
/**
88-
* Create a snapshot of the current DB and data folder state.
89-
*
90-
* @return string the ID of the snapshot
91-
*/
92-
saveState(): Cypress.Chainable<string>
93-
94-
/**
95-
* Restore a snapshot of the database
96-
* Default is the post-setup state
97-
*
98-
* @param snapshot string the ID of the snapshot
99-
*/
100-
restoreState(snapshot?: string): Cypress.Chainable<void>
101-
102-
/**
103-
* Run a command in the docker container
104-
*
105-
*/
106-
runCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>
107-
108-
/**
109-
* Run an occ command
110-
*/
111-
runOccCommand(command: string, options?: Partial<Cypress.ExecOptions>): Cypress.Chainable<Cypress.Exec>
112-
}
113-
}
114-
}
115-
116-
/**
117-
* Register all existing commands provided by this library
118-
*
119-
* You can also manually register those commands by importing them
120-
* @example import { login } from '@nextcloud/e2e-test-server/commands'
121-
* Cypress.Commands.add('login', login)
122-
*/
123-
export const addCommands = function() {
124-
Cypress.Commands.add('getNc', getNc)
125-
Cypress.Commands.add('login', login)
126-
Cypress.Commands.add('logout', logout)
127-
Cypress.Commands.add('createRandomUser', createRandomUser)
128-
Cypress.Commands.add('createUser', createUser)
129-
Cypress.Commands.add('deleteUser', deleteUser)
130-
Cypress.Commands.add('listUsers', listUsers)
131-
Cypress.Commands.add('modifyUser', modifyUser)
132-
Cypress.Commands.add('enableUser', enableUser)
133-
Cypress.Commands.add('getUserData', getUserData)
134-
Cypress.Commands.add('saveState', saveState)
135-
Cypress.Commands.add('restoreState', restoreState)
136-
Cypress.Commands.add('runCommand', runCommand)
137-
Cypress.Commands.add('runOccCommand', runOccCommand)
138-
}
139-
140-
export { User }
6+
export * from "./docker"
7+
export * from "./User"

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
"import": "./dist/docker.mjs",
2525
"require": "./dist/docker.js"
2626
},
27+
"./cypress": {
28+
"types": "./dist/cypress.d.ts",
29+
"import": "./dist/cypress.mjs",
30+
"require": "./dist/cypress.js"
31+
},
2732
".": {
2833
"types": "./dist/index.d.ts",
2934
"import": "./dist/index.js",

0 commit comments

Comments
 (0)