Skip to content

Commit

Permalink
Fix security vulnerabilities, bump Mocha, fix macOS tests (#1402)
Browse files Browse the repository at this point in the history
* Bump node-fetch from 2.6.0 to 2.6.1 in /test/smoke/package

Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Bump mocha, fix sec vulnerabilities

* Fix semantic errors

* Reorganize tests

* Fixate version for unit tests

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Yuri Skorokhodov <v-yuskor@microsoft.com>
  • Loading branch information
dependabot[bot] and SounD120 committed Sep 21, 2020
1 parent d55f3c2 commit 30806f6
Show file tree
Hide file tree
Showing 17 changed files with 557 additions and 220 deletions.
8 changes: 4 additions & 4 deletions .ci/common-validation.yml
Expand Up @@ -19,13 +19,13 @@ steps:
displayName: Start xvfb
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
- bash: npm run test-localization
displayName: "Run localization tests"
- bash: "npm test --verbose"
displayName: "Run host tests"
env:
DISPLAY: ":99.0"

- bash: "npm test --verbose"
displayName: "Run host tests"
- bash: npm run test-localization
displayName: "Run localization tests"
env:
DISPLAY: ":99.0"

Expand Down
511 changes: 393 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -844,7 +844,7 @@
"@types/configstore": "^4.0.0",
"@types/ip": "^1.1.0",
"@types/mkdirp": "^1.0.0",
"@types/mocha": "^7.0.2",
"@types/mocha": "^8.0.3",
"@types/ncp": "^2.0.3",
"@types/node": "^10.17.26",
"@types/qr-image": "^3.2.3",
Expand Down Expand Up @@ -875,7 +875,7 @@
"gulp-typescript": "^5.0.1",
"isparta": "^4.1.1",
"minimist": "^1.2.5",
"mocha": "^7.1.1",
"mocha": "^8.1.3",
"mocha-junit-reporter": "^1.23.3",
"mocha-multi-reporters": "^1.1.7",
"ncp": "^2.0.0",
Expand Down
10 changes: 5 additions & 5 deletions test/common/error/errorHelper.test.ts
Expand Up @@ -12,28 +12,28 @@ suite("errorHelper", function() {
const warning = ErrorHelper.getWarning("Warning");
const nestedWarning = ErrorHelper.getNestedWarning(new Error("Nested ES Error"), "Warning");

test("internal error object with arguments should have correct NotAllSuccessPatternsMatched error message on English", (done: MochaDone) => {
test("internal error object with arguments should have correct NotAllSuccessPatternsMatched error message on English", (done: Mocha.Done) => {
assert.equal(internalErrorWithArgs.message, "Unknown error: not all success patterns were matched. \n It means that \"react-native run-android\" command failed. \n Please, check the View -> Toggle Output -> React Native, \n View -> Toggle Output -> React Native: Run ios output windows. (error code 712)");
done();
});

test("internal error object without arguments should have correct UnsupportedCommandStatus error message on English", (done: MochaDone) => {
test("internal error object without arguments should have correct UnsupportedCommandStatus error message on English", (done: Mocha.Done) => {
assert.equal(internalErrorWithoutArgs.message, "Unsupported command status (error code 112)");
done();
});

test("nested error object with arguments should have correct error message on English", (done: MochaDone) => {
test("nested error object with arguments should have correct error message on English", (done: Mocha.Done) => {
assert.equal(nestedErrorWithArgs.message, "Error while executing command 'Command failed with ES Error': Nested ES Error");
done();
});

test("warning object should have correct error message on English", (done: MochaDone) => {
test("warning object should have correct error message on English", (done: Mocha.Done) => {
assert.equal(warning.errorCode, -1);
assert.equal(warning.message, "Warning");
done();
});

test("nested warning object should have correct error message on English", (done: MochaDone) => {
test("nested warning object should have correct error message on English", (done: Mocha.Done) => {
assert.equal(nestedWarning.errorCode, -1);
assert.equal(nestedWarning.message, "Warning: Nested ES Error");
done();
Expand Down
6 changes: 3 additions & 3 deletions test/common/log.test.ts
Expand Up @@ -17,20 +17,20 @@ suite("logHelper", function() {
process.env.REACT_NATIVE_TOOLS_LOGS_DIR = REACT_NATIVE_TOOLS_LOGS_DIR;
});

test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is not defined", (done: MochaDone) => {
test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is not defined", (done: Mocha.Done) => {
let loggingDir = getLoggingDirectory();
assert.strictEqual(loggingDir, null);
done();
});

test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by relative path", (done: MochaDone) => {
test("getLoggingDirectory should return null if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by relative path", (done: Mocha.Done) => {
process.env.REACT_NATIVE_TOOLS_LOGS_DIR = "./logs";
let loggingDir = getLoggingDirectory();
assert.strictEqual(loggingDir, null);
done();
});

test("getLoggingDirectory should return correct value if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by absolute path", (done: MochaDone) => {
test("getLoggingDirectory should return correct value if env variable REACT_NATIVE_TOOLS_LOGS_DIR is defined by absolute path", (done: Mocha.Done) => {
process.env.REACT_NATIVE_TOOLS_LOGS_DIR = path.join(__dirname, "testFolder");
let loggingDir = getLoggingDirectory();
assert.strictEqual(loggingDir, process.env.REACT_NATIVE_TOOLS_LOGS_DIR);
Expand Down
8 changes: 4 additions & 4 deletions test/common/projectVersionHelper.test.ts
Expand Up @@ -61,7 +61,7 @@ suite("projectVersionHelper", function() {
fsHelper.removePathRecursivelySync(path.join(sampleReactNative022ProjectDir, "node_modules"));
});

test("getReactNativePackageVersionsFromNodeModules should return object containing packages versions if 'version' field is found in react-native and react-native-windows packages package.json files from node_modules", (done: MochaDone) => {
test("getReactNativePackageVersionsFromNodeModules should return object containing packages versions if 'version' field is found in react-native and react-native-windows packages package.json files from node_modules", (done: Mocha.Done) => {
const reactNativeVersionObj = {
"version": "^0.20.0",
};
Expand Down Expand Up @@ -102,7 +102,7 @@ suite("projectVersionHelper", function() {
});
});

test("isVersionError should return true if a version string contains an error substring", (done: MochaDone) => {
test("isVersionError should return true if a version string contains an error substring", (done: Mocha.Done) => {
assert.equal(ProjectVersionHelper.isVersionError(RN_VERSION_ERRORS.MISSING_DEPENDENCIES_FIELDS_IN_PROJECT_PACKAGE_FILE), true);
assert.equal(ProjectVersionHelper.isVersionError(RN_VERSION_ERRORS.MISSING_PACKAGE_IN_NODE_MODULES), true);
assert.equal(ProjectVersionHelper.isVersionError(RN_VERSION_ERRORS.MISSING_DEPENDENCY_IN_PROJECT_PACKAGE_FILE), true);
Expand All @@ -113,7 +113,7 @@ suite("projectVersionHelper", function() {
done();
});

test("isVersionError should return false if a version string doesn't contain an error substring", (done: MochaDone) => {
test("isVersionError should return false if a version string doesn't contain an error substring", (done: Mocha.Done) => {
assert.equal(ProjectVersionHelper.isVersionError("^0.60.0-vnext.68"), false);
assert.equal(ProjectVersionHelper.isVersionError("https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz"), false);
assert.equal(ProjectVersionHelper.isVersionError("SemverInvalid"), false);
Expand All @@ -124,7 +124,7 @@ suite("projectVersionHelper", function() {
done();
});

test("processVersion should return semver valid version strings or correct error strings", (done: MochaDone) => {
test("processVersion should return semver valid version strings or correct error strings", (done: Mocha.Done) => {

assert.equal(ProjectVersionHelper.processVersion("^0.60.0-vnext.68", false), "0.60.0-vnext.68");
assert.equal(ProjectVersionHelper.processVersion("=v0.60.0-vnext.68", false), "0.60.0-vnext.68");
Expand Down
12 changes: 6 additions & 6 deletions test/debugger/appWorker.test.ts
Expand Up @@ -416,7 +416,7 @@ suite("appWorker", function () {
});

suite("console.trace()", function () {
function runScriptAndCheckOutput(expectedTraceMessage: string, consoleTraceCall: string, done: MochaDone): void {
function runScriptAndCheckOutput(expectedTraceMessage: string, consoleTraceCall: string, done: Mocha.Done): void {
const script = [MultipleLifetimesAppWorker.CONSOLE_TRACE_PATCH, consoleTraceCall].join("\n");
const testProcess = child_process.spawn("node", ["-e", script]);
let procData: string = "";
Expand Down Expand Up @@ -445,27 +445,27 @@ suite("appWorker", function () {
});
}

test("console.trace() patch should produce a correct output if called without args", (done: MochaDone) => {
test("console.trace() patch should produce a correct output if called without args", (done: Mocha.Done) => {
const consoleTraceCall = `console.trace();`;
const expectedTraceMessage = "Trace";
runScriptAndCheckOutput(expectedTraceMessage, consoleTraceCall, done);
});

test("console.trace() patch should produce a correct output if called with simple args", (done: MochaDone) => {
test("console.trace() patch should produce a correct output if called with simple args", (done: Mocha.Done) => {
const consoleTraceCall = `console.trace(\"Simple string\", 1337);`;
const expectedTraceMessage = "Trace: Simple string 1337";
runScriptAndCheckOutput(expectedTraceMessage, consoleTraceCall, done);
});

test("console.trace() patch should produce a correct output if called with formatted string", (done: MochaDone) => {
test("console.trace() patch should produce a correct output if called with formatted string", (done: Mocha.Done) => {
const consoleTraceCall = `console.trace("%s: %d", "Format string prints", 42);`;
const expectedTraceMessage = "Trace: Format string prints: 42";
runScriptAndCheckOutput(expectedTraceMessage, consoleTraceCall, done);
});
});

suite("process.toString()", function() {
test("process.toString() should return empty string to avoid errors in native app", (done: MochaDone) => {
test("process.toString() should return empty string to avoid errors in native app", (done: Mocha.Done) => {
const nodeProcessCheckToStringReturnCommand = "console.log(process.toString());";
const nodeProcessCheckCommand = "console.log(Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]');";
const script = [MultipleLifetimesAppWorker.PROCESS_TO_STRING_PATCH, nodeProcessCheckToStringReturnCommand, nodeProcessCheckCommand].join("\n");
Expand Down Expand Up @@ -496,7 +496,7 @@ suite("appWorker", function () {
});

suite("node --no-deprecation tests", function() {
test("node process should work with --no-deprecation flag and produce no deprecation warnings for Buffer function and GLOBAL variable usage", (done: MochaDone) => {
test("node process should work with --no-deprecation flag and produce no deprecation warnings for Buffer function and GLOBAL variable usage", (done: Mocha.Done) => {
const globalVariableCheck = "GLOBAL.toString();";
const bufferCommandCheck = "Buffer('TestString');";
const script = [globalVariableCheck, bufferCommandCheck].join("\n");
Expand Down
4 changes: 2 additions & 2 deletions test/extension/commandExecutor.test.ts
Expand Up @@ -173,15 +173,15 @@ suite("commandExecutor", function() {
["react-native-tools.reactNativeGlobalCommandName"]: "",
};

test("selectReactNativeCLI should return local CLI", (done: MochaDone) => {
test("selectReactNativeCLI should return local CLI", (done: Mocha.Done) => {
const localCLIPath = path.join(sampleReactNative022ProjectDir, "node_modules", ".bin", "react-native");
let commandExecutor: CommandExecutor = new CommandExecutor(sampleReactNative022ProjectDir);
CommandExecutor.ReactNativeCommand = RNGlobalCLINameContent["react-native-tools.reactNativeGlobalCommandName"];
assert.equal(commandExecutor.selectReactNativeCLI(), localCLIPath);
done();
});

test("selectReactNativeCLI should return global CLI", (done: MochaDone) => {
test("selectReactNativeCLI should return global CLI", (done: Mocha.Done) => {
const randomHash = new Crypto().hash(Math.random().toString(36).substring(2, 15));
RNGlobalCLINameContent["react-native-tools.reactNativeGlobalCommandName"] = randomHash;
let commandExecutor: CommandExecutor = new CommandExecutor(sampleReactNative022ProjectDir);
Expand Down
4 changes: 2 additions & 2 deletions test/extension/elementInspector.test.ts
Expand Up @@ -8,7 +8,7 @@ import * as assert from "assert";
suite("elementInspector", function() {
suite("extensionContext", function () {

test("element inspector should run and closed without errors", function(done: MochaDone) {
test("element inspector should run and closed without errors", function (done: Mocha.Done) {
CommandPaletteHandler.runElementInspector();
assert.notEqual(CommandPaletteHandler.elementInspector, null);

Expand All @@ -23,7 +23,7 @@ suite("elementInspector", function() {
CommandPaletteHandler.stopElementInspector();
});

test("element inspector should not allow multiple windows to run", function(done: MochaDone) {
test("element inspector should not allow multiple windows to run", function (done: Mocha.Done) {
CommandPaletteHandler.runElementInspector();
if (CommandPaletteHandler.elementInspector) {
let PID = CommandPaletteHandler.elementInspector.pid;
Expand Down
2 changes: 1 addition & 1 deletion test/index.ts
Expand Up @@ -18,9 +18,9 @@ export function run(): Promise<void> {
mochaFile: path.join(__dirname, "ExtensionTests.xml"),
},
},
color: true,
});

mocha.useColors(true);
mocha.invert();

const testsRoot = __dirname;
Expand Down
3 changes: 1 addition & 2 deletions test/localization/index.ts
Expand Up @@ -15,10 +15,9 @@ export function run(): Promise<void> {
mochaFile: path.join(__dirname, "..", "LocalizationTests.xml"),
},
},
color: true,
});

mocha.useColors(true);

// Register Mocha options
return new Promise((resolve, reject) => {
mocha.addFile(path.resolve(__dirname, "localization.test.js"));
Expand Down
4 changes: 2 additions & 2 deletions test/localization/localization.test.ts
Expand Up @@ -9,12 +9,12 @@ suite("localizationTest", function() {
suite("localizationContext", function () {
const commandFailedErrorRu = ErrorHelper.getInternalError(InternalErrorCode.CommandFailed, "Команда");
const iosDeployErrorRu = ErrorHelper.getInternalError(InternalErrorCode.IOSDeployNotFound);
test("localize should show correct message on Russian for CommandFailed error", (done: MochaDone) => {
test("localize should show correct message on Russian for CommandFailed error", (done: Mocha.Done) => {
assert.strictEqual(commandFailedErrorRu.message, "Ошибка при выполнении команды \"Команда\" (error code 101)");
done();
});

test("localize should show correct message on Russian for iOSDeployNotFound error", (done: MochaDone) => {
test("localize should show correct message on Russian for iOSDeployNotFound error", (done: Mocha.Done) => {
assert.strictEqual(iosDeployErrorRu.message,
"Не удается найти ios-deploy. Установите его на глобальном уровне (\"npm install -g ios-deploy\") (error code 201)");
done();
Expand Down
1 change: 1 addition & 0 deletions test/localization/runTest.ts
Expand Up @@ -20,6 +20,7 @@ async function launchTests() {
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ["--locale", "ru"],
version: "1.48.0"
});
} catch (err) {
console.error(err);
Expand Down
14 changes: 7 additions & 7 deletions test/resources/recordingsHelper.ts
Expand Up @@ -7,12 +7,12 @@ import * as path from "path";
const RECORDINGS_ROOT = path.resolve(__dirname, "processExecutionsRecordings");

interface TestUsingRecording {
(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.ITest;
(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): Mocha.ITest;
only(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.ITest;
only(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): Mocha.ITest;
(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.Test;
(expectation: string, recordingNames: string[], assertion?: (done: Mocha.Done) => void): Mocha.Test;
only(expectation: string, recordingNames: string[], assertion?: () => void): Mocha.Test;
only(expectation: string, recordingNames: string[], assertion?: (done: Mocha.Done) => void): Mocha.Test;
skip(expectation: string, recordingNames: string[], assertion?: () => void): void;
skip(expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void): void;
skip(expectation: string, recordingNames: string[], assertion?: (done: Mocha.Done) => void): void;
}

export interface IRecordingConsumer {
Expand Down Expand Up @@ -43,7 +43,7 @@ export class RecordingsHelper {
private initializeTest(): void {
this.test = <TestUsingRecording>((testName: string, recordingNames: string[], code: () => Promise<void>): void => {
if (code.length !== 0) { // Check how many arguments the function has
throw new RangeError("(done: mochaDone) parameter is not supported. Please return a promise instead.");
throw new RangeError("(done: Mocha.Done) parameter is not supported. Please return a promise instead.");
}
const recordingsHelper = this;
recordingNames.forEach(recordingName => {
Expand All @@ -62,7 +62,7 @@ export class RecordingsHelper {
});
});
});
this.test.skip = (expectation: string, recordingNames: string[], assertion?: (done: MochaDone) => void) => {
this.test.skip = (expectation: string, recordingNames: string[], assertion?: (done: Mocha.Done) => void) => {
test.skip(expectation, assertion);
};
}
Expand Down
1 change: 1 addition & 0 deletions test/runTest.ts
Expand Up @@ -19,6 +19,7 @@ async function launchTests() {
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
version: "1.48.0"
});
} catch (err) {
console.error(err);
Expand Down
6 changes: 4 additions & 2 deletions test/smoke/package/package.json
Expand Up @@ -44,9 +44,11 @@
},
"resolutions": {
"@expo/xdl/analytics-node/axios": "^0.19.0",
"**/serialize-javascript": "^2.1.1",
"**/serialize-javascript": "^3.1.0",
"**/tree-kill": "^1.2.2",
"**/minimist": "^1.2.3",
"lodash": "^4.17.19"
"lodash": "^4.17.19",
"dot-prop": "^5.2.0",
"bl": "^1.2.3"
}
}

0 comments on commit 30806f6

Please sign in to comment.