From 1a4e3d94a6f1509b17071222b3d73f3bc50cce57 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Wed, 30 Oct 2024 00:11:45 -0300 Subject: [PATCH] fix(test): file.spec.131 moveTo may fail due to read order assumption --- tests/tests.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/tests.js b/tests/tests.js index 676d6fe7..8e5d65c3 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1941,8 +1941,18 @@ exports.defineAutoTests = function () { directoryReader.readEntries(function successRead (entries) { expect(entries.length).toBe(2); if (!isChrome) { - expect(entries[0].name).toBe(srcDirNestedFirst); - expect(entries[1].name).toBe(srcDirNestedSecond); + // Directory read order is undefined on some platforms, therefore we cannot assume order + // So we will start with an expected list and iterate over the entries and test to see if they + // are in our expectation list. When found we will remove them. At the end, our expectation list + // should be empty. + const expected = [srcDirNestedFirst, srcDirNestedSecond]; + for (let i = 0; i < entries.length; i++) { + const index = expected.indexOf(entries[i].name); + expect(index).toBeGreaterThan(-1); + expected.splice(index, 1); + } + + expect(expected.length).toBe(0); } deleteEntry(dstDir, done); }, failed.bind(null, done, 'Error getting entries from: ' + transferredDirectory));