From 7839900b0de411cbec1d90f788785741ffa03d95 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 25 Feb 2021 10:10:08 -0800 Subject: [PATCH] fix(test): update hidden package-lock mtime in ls That file must be newer than the others for the code to do what we are expecting PR-URL: https://github.com/npm/cli/pull/2782 Credit: @isaacs Close: #2782 Reviewed-by: @wraithgar --- test/lib/ls.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/lib/ls.js b/test/lib/ls.js index a89137b9ef094..b1df9067c3d57 100644 --- a/test/lib/ls.js +++ b/test/lib/ls.js @@ -3,6 +3,12 @@ const { resolve } = require('path') const t = require('tap') const requireInject = require('require-inject') +const { utimesSync } = require('fs') +const touchHiddenPackageLock = prefix => { + const later = new Date(Date.now() + 10000) + utimesSync(`${prefix}/node_modules/.package-lock.json`, later, later) +} + t.cleanSnapshot = str => str.split(/\r\n/).join('\n') const simpleNmFixture = { @@ -1186,6 +1192,7 @@ t.test('ls', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.matchSnapshot(redactCwd(result), 'should output tree containing aliases') t.end() @@ -1231,6 +1238,7 @@ t.test('ls', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], (err) => { t.ifError(err, 'npm ls') t.matchSnapshot(redactCwd(result), 'should output tree containing git refs') @@ -1329,6 +1337,7 @@ t.test('ls', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.matchSnapshot(redactCwd(result), 'should not be printed in tree output') t.end() @@ -2228,6 +2237,7 @@ t.test('ls --parseable', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.matchSnapshot(redactCwd(result), 'should output tree containing aliases') t.end() @@ -2272,6 +2282,7 @@ t.test('ls --parseable', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.matchSnapshot(redactCwd(result), 'should output tree containing git refs') t.end() @@ -2325,6 +2336,7 @@ t.test('ls --parseable', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.matchSnapshot(redactCwd(result), 'should not be printed in tree output') t.end() @@ -3688,6 +3700,7 @@ t.test('ls --json', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.deepEqual( jsonParse(result), @@ -3747,6 +3760,7 @@ t.test('ls --json', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.deepEqual( jsonParse(result), @@ -3830,6 +3844,7 @@ t.test('ls --json', (t) => { }, }, }) + touchHiddenPackageLock(prefix) ls([], () => { t.deepEqual( jsonParse(result),