Skip to content

Commit

Permalink
fix(types,base-driver): remove deviceName from base constraints
Browse files Browse the repository at this point in the history
This cap was conflicting with constraints defined in subclasses.  Currently, it isn't possible to cleanly "override" constraints.  Given `deviceName` is not used anywhere within base-driver's source, this seems like a decent workaround for now.
  • Loading branch information
boneskull committed Jul 3, 2023
1 parent 24e7aec commit 01061b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 65 deletions.
92 changes: 31 additions & 61 deletions packages/base-driver/test/unit/basedriver/capability.spec.js
Expand Up @@ -36,18 +36,15 @@ describe('Desired Capabilities', function () {
it('should require platformName', async function () {
await d
.createSession({
alwaysMatch: {
'appium:deviceName': 'Delorean',
},
alwaysMatch: {},
firstMatch: [{}],
})
.should.be.rejectedWith(errors.SessionNotCreatedError, /platformName/);
});

it('should not care about cap order', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
'appium:deviceName': 'Delorean',
platformName: 'iOS',
},
firstMatch: [{}],
Expand All @@ -67,10 +64,9 @@ describe('Desired Capabilities', function () {
};

await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
},
firstMatch: [{}],
})
Expand All @@ -90,7 +86,7 @@ describe('Desired Capabilities', function () {
});

await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
'appium:necessary': 'yup',
},
Expand All @@ -100,28 +96,22 @@ describe('Desired Capabilities', function () {
});

it('should accept extra capabilities', async function () {
await d.createSession(
null,
null,
/** @type {import('@appium/types').W3CCapabilities<{'hold the':string}>} */ ({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:extra': 'cheese',
'appium:hold the': 'sauce',
},
firstMatch: [{}],
})
).should.be.fulfilled;
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:extra': 'cheese',
'appium:hold the': 'sauce',
},
firstMatch: [{}],
}).should.be.fulfilled;
});

it('should log the use of extra caps', async function () {
this.timeout(500);

await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:extra': 'cheese',
'appium:hold the': 'sauce',
},
Expand All @@ -133,11 +123,10 @@ describe('Desired Capabilities', function () {

it('should be sensitive to the case of caps', async function () {
await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
// @ts-expect-error
platformname: 'iOS',
'appium:deviceName': 'Delorean',
},
firstMatch: [{}],
})
Expand All @@ -146,10 +135,9 @@ describe('Desired Capabilities', function () {

describe('boolean capabilities', function () {
it('should allow a string "false"', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
// @ts-expect-error
'appium:noReset': 'false',
},
Expand All @@ -162,10 +150,9 @@ describe('Desired Capabilities', function () {
});

it('should allow a string "true"', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
// @ts-expect-error
'appium:noReset': 'true',
},
Expand All @@ -178,10 +165,9 @@ describe('Desired Capabilities', function () {
});

it('should allow a string "true" in string capabilities', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:language': 'true',
},
firstMatch: [{}],
Expand All @@ -195,10 +181,9 @@ describe('Desired Capabilities', function () {

describe('number capabilities', function () {
it('should allow a string "1"', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
// @ts-expect-error
'appium:newCommandTimeout': '1',
},
Expand All @@ -211,10 +196,9 @@ describe('Desired Capabilities', function () {
});

it('should allow a string "1.1"', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
// @ts-expect-error
'appium:newCommandTimeout': '1.1',
},
Expand All @@ -227,10 +211,9 @@ describe('Desired Capabilities', function () {
});

it('should allow a string "1" in string capabilities', async function () {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:language': '1',
},
firstMatch: [{}],
Expand All @@ -244,11 +227,10 @@ describe('Desired Capabilities', function () {

it('should error if objects in caps', async function () {
await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
// @ts-expect-error
platformName: {a: 'iOS'},
'appium:deviceName': 'Delorean',
},
firstMatch: [{}],
})
Expand All @@ -264,10 +246,9 @@ describe('Desired Capabilities', function () {
},
};

await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:lynx-version': 5,
},
firstMatch: [{}],
Expand All @@ -285,10 +266,9 @@ describe('Desired Capabilities', function () {
},
};

await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
'appium:lynx-version': 5,
},
firstMatch: [{}],
Expand All @@ -305,10 +285,9 @@ describe('Desired Capabilities', function () {
};

try {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': null,
},
firstMatch: [{}],
Expand All @@ -318,21 +297,19 @@ describe('Desired Capabilities', function () {
}

await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': 1,
},
firstMatch: [{}],
})
.should.be.rejectedWith(/'foo' must be of type string/);

try {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': undefined,
},
firstMatch: [{}],
Expand All @@ -342,10 +319,9 @@ describe('Desired Capabilities', function () {
}

try {
await d.createSession(null, null, {
await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': '',
},
firstMatch: [{}],
Expand All @@ -363,21 +339,20 @@ describe('Desired Capabilities', function () {
};

await d
.createSession(null, null, {
.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': null,
},
firstMatch: [{}],
})
.should.be.rejectedWith(/blank/);

await d
// @ts-expect-error `null` is not actually allowed here
.createSession(null, {
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': '',
},
firstMatch: [{}],
Expand All @@ -389,7 +364,6 @@ describe('Desired Capabilities', function () {
firstMatch: [
{
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': {},
},
],
Expand All @@ -401,7 +375,6 @@ describe('Desired Capabilities', function () {
.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': [],
},
firstMatch: [{}],
Expand All @@ -412,7 +385,6 @@ describe('Desired Capabilities', function () {
.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Dumb',
'appium:foo': ' ',
},
firstMatch: [{}],
Expand All @@ -422,17 +394,15 @@ describe('Desired Capabilities', function () {

describe('w3c', function () {
it('should accept w3c capabilities', async function () {
const [sessionId, caps] = await d.createSession(null, null, {
const [sessionId, caps] = await d.createSession({
alwaysMatch: {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
},
firstMatch: [{}],
});
sessionId.should.exist;
caps.should.eql({
platformName: 'iOS',
deviceName: 'Delorean',
});
});

Expand All @@ -442,7 +412,7 @@ describe('Desired Capabilities', function () {
await B.map(testValues, (val) =>
d
// @ts-expect-error
.createSession(null, null, val)
.createSession(val)
.should.be.rejectedWith(errors.SessionNotCreatedError)
);
});
Expand Down
5 changes: 1 addition & 4 deletions packages/types/lib/constraints.ts
@@ -1,4 +1,4 @@
import {Constraints} from './driver';
import type {Constraints} from './driver';

export const BASE_DESIRED_CAP_CONSTRAINTS = {
platformName: {
Expand All @@ -8,9 +8,6 @@ export const BASE_DESIRED_CAP_CONSTRAINTS = {
app: {
isString: true,
},
deviceName: {
isString: true,
},
platformVersion: {
isString: true,
},
Expand Down

0 comments on commit 01061b2

Please sign in to comment.