From 49dc495acaf53bb5f612e2e1552dc5dc40d1c62f Mon Sep 17 00:00:00 2001 From: jleyba Date: Thu, 6 Jun 2019 15:06:41 -0700 Subject: [PATCH] [js] fix test to use a stable ordering for test comparisons --- .../selenium-webdriver/test/io/io_test.js | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/javascript/node/selenium-webdriver/test/io/io_test.js b/javascript/node/selenium-webdriver/test/io/io_test.js index c8ec6a16c5fc0..63fe583f6f327 100644 --- a/javascript/node/selenium-webdriver/test/io/io_test.js +++ b/javascript/node/selenium-webdriver/test/io/io_test.js @@ -339,22 +339,26 @@ describe('io', function() { }); describe('walkDir', function() { - it('walk directory', function() { - return io.tmpDir().then(dir => { - fs.writeFileSync(path.join(dir, 'file1'), 'hello'); - fs.mkdirSync(path.join(dir, 'sub')); - fs.mkdirSync(path.join(dir, 'sub/folder')); - fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye'); - - return io.walkDir(dir).then(seen => { - assert.deepStrictEqual( - seen, - [{path: 'file1', dir: false}, - {path: 'sub', dir: true}, - {path: path.join('sub', 'folder'), dir: true}, - {path: path.join('sub', 'folder', 'file2'), dir: false}]); - }); + it('walk directory', async function() { + let dir = await io.tmpDir(); + + fs.writeFileSync(path.join(dir, 'file1'), 'hello'); + fs.mkdirSync(path.join(dir, 'sub')); + fs.mkdirSync(path.join(dir, 'sub/folder')); + fs.writeFileSync(path.join(dir, 'sub/folder/file2'), 'goodbye'); + + let seen = await io.walkDir(dir); + seen.sort((a, b) => { + if (a.path < b.path) return -1; + if (a.path > b.path) return 1; + return 0; }); + assert.deepStrictEqual( + seen, + [{path: 'file1', dir: false}, + {path: 'sub', dir: true}, + {path: path.join('sub', 'folder'), dir: true}, + {path: path.join('sub', 'folder', 'file2'), dir: false}]); }); }) });