Skip to content

Commit 008980d

Browse files
authored
Fix running Hardware tests (#531)
When running HW tests with RUN_DEVICE_TESTS=true yarn test the HW tests all failed with: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. Basically the test framework no longer allows to return a Promise and to end with a callback. As the callback was only used with the return promise anyhow, I simplified the code by dropping the done callback, just using the promise. Signed-off-by: Daniel Friederich <[email protected]>
1 parent 75cd64f commit 008980d

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

test/adb/sync.ts

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('Sync', function () {
3030
let client!: Client;
3131
let deviceList: Device[] | null = null;
3232
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33-
const forEachSyncDevice = function (iterator: (sync: Sync) => any, done): Promise<Sync> {
34-
assert(deviceList.length > 0, 'At least one connected Android device is required');
33+
const forEachSyncDevice = function (iterator: (sync: Sync) => any): Promise<void> {
34+
assert(deviceList && deviceList.length > 0, 'At least one connected Android device is required');
3535
const promises = deviceList.map(function (device) {
3636
return client
3737
.getDevice(device.id)
@@ -43,9 +43,7 @@ describe('Sync', function () {
4343
});
4444
});
4545
});
46-
return Promise.all(promises)
47-
.then(() => done())
48-
.catch(done);
46+
return Promise.all(promises).then()
4947
};
5048
before(function () {
5149
if (process.env.RUN_DEVICE_TESTS) {
@@ -99,7 +97,7 @@ describe('Sync', function () {
9997
expect(transfer).to.be.an.instanceof(PushTransfer);
10098
return transfer.cancel();
10199
});
102-
return dt('should be able to push >65536 byte chunks without error', function (done) {
100+
return dt('should be able to push >65536 byte chunks without error', function () {
103101
return forEachSyncDevice(function (sync) {
104102
return new Promise(function (resolve, reject) {
105103
const stream = new Stream.PassThrough();
@@ -110,11 +108,11 @@ describe('Sync', function () {
110108
stream.write(content);
111109
return stream.end();
112110
});
113-
}, done);
111+
});
114112
});
115113
});
116114
describe('pull(path)', function () {
117-
dt('should retrieve the same content pushStream() pushed', function (done) {
115+
dt('should retrieve the same content pushStream() pushed', function () {
118116
return forEachSyncDevice(function (sync) {
119117
return new Promise(function (resolve, reject) {
120118
const stream = new Stream.PassThrough();
@@ -138,45 +136,45 @@ describe('Sync', function () {
138136
stream.write(content);
139137
return stream.end();
140138
});
141-
}, done);
139+
});
142140
});
143-
dt('should emit error for non-existing files', function (done) {
141+
dt('should emit error for non-existing files', function () {
144142
return forEachSyncDevice(function (sync) {
145143
return new Promise(function (resolve) {
146144
const transfer = sync.pull(SURELY_NONEXISTING_PATH);
147145
return transfer.on('error', resolve);
148146
});
149-
}, done);
147+
});
150148
});
151-
dt('should return a PullTransfer instance', function (done) {
149+
dt('should return a PullTransfer instance', function () {
152150
return forEachSyncDevice(function (sync) {
153151
const rval = sync.pull(SURELY_EXISTING_FILE);
154152
expect(rval).to.be.an.instanceof(PullTransfer);
155153
return rval.cancel();
156-
}, done);
154+
});
157155
});
158156
return describe('Stream', function () {
159-
return dt("should emit 'end' when pull is done", function (done) {
157+
return dt("should emit 'end' when pull is done", function () {
160158
return forEachSyncDevice(function (sync) {
161159
return new Promise(function (resolve, reject) {
162160
const transfer = sync.pull(SURELY_EXISTING_FILE);
163161
transfer.on('error', reject);
164162
transfer.on('end', resolve);
165163
return transfer.resume();
166164
});
167-
}, done);
165+
});
168166
});
169167
});
170168
});
171169
return describe('stat(path)', function () {
172-
dt('should return a Promise', function (done) {
170+
dt('should return a Promise', function () {
173171
return forEachSyncDevice(function (sync) {
174172
const rval = sync.stat(SURELY_EXISTING_PATH);
175173
expect(rval).to.be.an.instanceof(Promise);
176174
return rval;
177-
}, done);
175+
});
178176
});
179-
dt('should call with an ENOENT error if the path does not exist', function (done) {
177+
dt('should call with an ENOENT error if the path does not exist', function () {
180178
return forEachSyncDevice(function (sync) {
181179
return sync
182180
.stat(SURELY_NONEXISTING_PATH)
@@ -189,54 +187,54 @@ describe('Sync', function () {
189187
expect(err.errno).to.equal(34);
190188
return expect(err.path).to.equal(SURELY_NONEXISTING_PATH);
191189
});
192-
}, done);
190+
});
193191
});
194-
dt('should call with an fs.Stats instance for an existing path', function (done) {
192+
dt('should call with an fs.Stats instance for an existing path', function () {
195193
return forEachSyncDevice(function (sync) {
196194
return sync.stat(SURELY_EXISTING_PATH).then(function (stats) {
197195
return expect(stats).to.be.an.instanceof(Fs.Stats);
198196
});
199-
}, done);
197+
});
200198
});
201199
describe('Stats', function () {
202200
it('should implement Fs.Stats', function (done) {
203201
expect(new Stats(0, BigInt(0), 0)).to.be.an.instanceof(Fs.Stats);
204202
done();
205203
});
206-
dt('should set the `.mode` property for isFile() etc', function (done) {
204+
dt('should set the `.mode` property for isFile() etc', function () {
207205
return forEachSyncDevice(function (sync) {
208206
return sync.stat(SURELY_EXISTING_FILE).then(function (stats) {
209207
expect(stats).to.be.an.instanceof(Fs.Stats);
210208
expect(stats.mode).to.be.above(0);
211209
expect(stats.isFile()).to.be.true;
212210
return expect(stats.isDirectory()).to.be.false;
213211
});
214-
}, done);
212+
});
215213
});
216-
dt('should set the `.size` property', function (done) {
214+
dt('should set the `.size` property', function () {
217215
return forEachSyncDevice(function (sync) {
218216
return sync.stat(SURELY_EXISTING_FILE).then(function (stats) {
219217
expect(stats).to.be.an.instanceof(Fs.Stats);
220218
expect(stats.isFile()).to.be.true;
221219
return expect(stats.size).to.be.above(0);
222220
});
223-
}, done);
221+
});
224222
});
225-
return dt('should set the `.mtime` property', function (done) {
223+
return dt('should set the `.mtime` property', function () {
226224
return forEachSyncDevice(function (sync) {
227225
return sync.stat(SURELY_EXISTING_FILE).then(function (stats) {
228226
expect(stats).to.be.an.instanceof(Fs.Stats);
229227
return expect(stats.mtime).to.be.an.instanceof(Date);
230228
});
231-
}, done);
229+
});
232230
});
233231
});
234232
return describe('Entry', function () {
235233
it('should implement Stats', function (done) {
236234
expect(new Entry('foo', 0, 0, 0)).to.be.an.instanceof(Stats);
237235
done();
238236
});
239-
dt('should set the `.name` property', function (done) {
237+
dt('should set the `.name` property', function () {
240238
return forEachSyncDevice(function (sync) {
241239
return sync.readdir(SURELY_EXISTING_PATH).then(function (files) {
242240
expect(files).to.be.an('Array');
@@ -245,9 +243,9 @@ describe('Sync', function () {
245243
return expect(file).to.be.an.instanceof(Entry);
246244
});
247245
});
248-
}, done);
246+
});
249247
});
250-
return dt('should set the Stats properties', function (done) {
248+
return dt('should set the Stats properties', function () {
251249
return forEachSyncDevice(function (sync) {
252250
return sync.readdir(SURELY_EXISTING_PATH).then(function (files) {
253251
expect(files).to.be.an('Array');
@@ -257,7 +255,7 @@ describe('Sync', function () {
257255
return expect(file.mtime).to.not.be.null;
258256
});
259257
});
260-
}, done);
258+
});
261259
});
262260
});
263261
});

0 commit comments

Comments
 (0)