Skip to content

Commit

Permalink
Add --no-msg argument
Browse files Browse the repository at this point in the history
And use in tests that check a script's output.
  • Loading branch information
Cykelero committed Jun 27, 2022
1 parent 6575718 commit e0ef63d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
7 changes: 5 additions & 2 deletions source/PackageCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const crossSpawn = require('cross-spawn');
const rimraf = require('rimraf');

const Constants = require('./Constants');
const Tools = require('./Tools');
const ScriptEnvironment = require('./ScriptEnvironment');
const RuntimeVersion = require('./RuntimeVersion');
const Tools = require('./Tools');

module.exports = {
PACKAGE_CACHE_PATH: path.join(Constants.CACHE_PATH, 'npm-packages', path.sep),
Expand Down Expand Up @@ -249,7 +250,9 @@ module.exports = {

_showPreparingMessage() {
if (!this._didRecentlyShowPreparingMessage) {
process.stdout.write('Preparing packages...\n');
if (!ScriptEnvironment.muteInfoMessages) {
process.stdout.write('Preparing packages...\n');
}

this._didRecentlyShowPreparingMessage = true;
setImmediate(() => {
Expand Down
3 changes: 2 additions & 1 deletion source/ScriptEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = {
requiredRuntimeVersion: null,
rawArguments: null,
defaultBundlePackageList: null,
requiredPackageVersions: null
requiredPackageVersions: null,
muteInfoMessages: null
};
1 change: 1 addition & 0 deletions source/ScriptRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
ScriptEnvironment.rawArguments = args;
ScriptEnvironment.defaultBundlePackageList = requiredPackages;
ScriptEnvironment.requiredPackageVersions = requiredPackageVersions;
//ScriptEnvironment.muteInfoMessages // Set in tasklemon.js

// Write script to stage
stagePath = fs.mkdtempSync(os.tmpdir() + path.sep);
Expand Down
15 changes: 12 additions & 3 deletions source/exposed-modules/Folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const glob = require('glob');

const Item = require('./Item');
const TypeDefinition = require('../TypeDefinition');
const ScriptEnvironment = require('../ScriptEnvironment');
const RuntimeVersion = require('../RuntimeVersion');

let didShowFileMethodDeprecationWarning = false;
Expand Down Expand Up @@ -59,7 +60,11 @@ class Folder extends Item {
if (Item._isAbsolutePath(nativePath)) {
if (!this._isRoot) throw Error(`“${cleanPath}” is an absolute path but the folder is not a root folder`);

if (!didShowFileMethodDeprecationWarning && RuntimeVersion.isAtLeast('0.4')) {
if (
!ScriptEnvironment.muteInfoMessages
&& !didShowFileMethodDeprecationWarning
&& RuntimeVersion.isAtLeast('0.4')
) {
didShowFileMethodDeprecationWarning = true;
console.trace('Calling the file() method with an absolute path is deprecated. Call the File() global instead.');
}
Expand All @@ -78,8 +83,12 @@ class Folder extends Item {
if (Item._isAbsolutePath(nativePath)) {
if (!this._isRoot) throw Error(`“${cleanPath}” is an absolute path but the folder is not a root folder`);


if (!didShowFolderMethodDeprecationWarning && RuntimeVersion.isAtLeast('0.4')) {

if (
!ScriptEnvironment.muteInfoMessages
&& !didShowFolderMethodDeprecationWarning
&& RuntimeVersion.isAtLeast('0.4')
) {
didShowFolderMethodDeprecationWarning = true;
console.trace('Calling the folder() method with an absolute path is deprecated. Call the Folder() global instead.');
}
Expand Down
8 changes: 7 additions & 1 deletion source/tasklemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const PackageCache = require('./PackageCache');
const ScriptFile = require('./ScriptFile');
const ScriptRunner = require('./ScriptRunner');
const ScriptParser = require('./ScriptParser');
const ScriptEnvironment = require('./ScriptEnvironment');
const Tools = require('./Tools');

const validLemonArguments = [
Expand All @@ -17,7 +18,10 @@ const validLemonArguments = [

// Package/runtime pinning
'--pin-pkg',
'--no-pin'
'--no-pin',

// Other
'--no-msg'
];
const validNodeArguments = ['--inspect', '--inspect-brk'];

Expand Down Expand Up @@ -110,6 +114,8 @@ function exitIfContainsInvalidArguments(args) {
const actionsToPerform = getActionsForForArguments(programArgs.lemonArguments);
const scriptFile = new ScriptFile(programArgs.scriptPath);

ScriptEnvironment.muteInfoMessages = programArgs.lemonArguments.includes('--no-msg');

// Clear package cache
if (actionsToPerform.clearPackageCache) {
const deletedBundleCount = PackageCache.clearAll();
Expand Down
16 changes: 8 additions & 8 deletions spec/npm/npmSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('npm', function() {
process.stdout.write(String(uniqueCount));
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('3');
});
Expand All @@ -26,7 +26,7 @@ describe('npm', function() {
}
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('success');
});
Expand All @@ -37,7 +37,7 @@ describe('npm', function() {
process.stdout.write(String(uniqueCount));
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('3');
});
Expand All @@ -48,7 +48,7 @@ describe('npm', function() {
process.stdout.write(String(stryker.cliOptions.concurrency));
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('4');
});
Expand All @@ -59,7 +59,7 @@ describe('npm', function() {
process.stdout.write(String(npm['@octokit/core'].Octokit.VERSION));
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('3.2.4');
});
Expand All @@ -73,7 +73,7 @@ describe('npm', function() {
}
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('success');
});
Expand All @@ -88,7 +88,7 @@ describe('npm', function() {
}
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg']);

expect(scriptOutput).toBe('success');
});
Expand All @@ -105,7 +105,7 @@ describe('npm', function() {
}
`;

let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-pin']);
let scriptOutput = await testEnv.runLemonScript(scriptSource, [], ['--no-msg', '--no-pin']);

expect(scriptOutput).toBe('success');
});
Expand Down

0 comments on commit e0ef63d

Please sign in to comment.