Skip to content

Commit 0b537f0

Browse files
authored
Prevent primitive linting limitations from being applied to unit tests found under src/setup_node_env (#3403)
Signed-off-by: Miki <[email protected]>
1 parent d9dc91d commit 0b537f0

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ module.exports = {
459459
* Files that run BEFORE node version check
460460
*/
461461
{
462-
files: ['scripts/**/*.js', 'src/setup_node_env/**/*.js'],
462+
files: ['scripts/**/*.js', 'src/setup_node_env/**/!(*.test).js'],
463463
rules: {
464464
'import/no-commonjs': 'off',
465465
'prefer-object-spread/prefer-object-spread': 'off',

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
142142
- [Tests] Bumps `chromedriver` to v107 ([#3017](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3017))
143143
- [Vis Builder] Adds field unit tests ([#3211](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3211))
144144
- [BWC Tests] Add BWC tests for 2.6.0 ([#3356](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3356))
145+
- Prevent primitive linting limitations from being applied to unit tests found under `src/setup_node_env` ([#3403](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3403))
145146

146147
## [2.x]
147148

src/setup_node_env/node_version_validator.test.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
* under the License.
2929
*/
3030

31-
var exec = require('child_process').exec;
32-
var pkg = require('../../package.json');
31+
const exec = require('child_process').exec;
32+
const pkg = require('../../package.json');
3333

34-
var REQUIRED_NODE_JS_VERSION = 'v' + pkg.engines.node;
34+
const REQUIRED_NODE_JS_VERSION = 'v' + pkg.engines.node;
3535

3636
describe('NodeVersionValidator', function () {
3737
it('should run the script WITHOUT error when the version is the same', function (done) {
@@ -43,7 +43,7 @@ describe('NodeVersionValidator', function () {
4343
});
4444

4545
it('should run the script WITH error if the patch version is lower', function (done) {
46-
var lowerPatchversion = requiredNodeVersionWithDiff(0, 0, -1);
46+
const lowerPatchversion = requiredNodeVersionWithDiff(0, 0, -1);
4747
testValidateNodeVersion(
4848
done,
4949
lowerPatchversion,
@@ -56,7 +56,7 @@ describe('NodeVersionValidator', function () {
5656
});
5757

5858
it('should run the script WITH error if the major version is lower', function (done) {
59-
var lowerMajorVersion = requiredNodeVersionWithDiff(-1, 0, 0);
59+
const lowerMajorVersion = requiredNodeVersionWithDiff(-1, 0, 0);
6060
testValidateNodeVersion(
6161
done,
6262
lowerMajorVersion,
@@ -69,7 +69,7 @@ describe('NodeVersionValidator', function () {
6969
});
7070

7171
it('should run the script WITH error if the minor version is lower', function (done) {
72-
var lowerMinorVersion = requiredNodeVersionWithDiff(0, -1, 0);
72+
const lowerMinorVersion = requiredNodeVersionWithDiff(0, -1, 0);
7373
testValidateNodeVersion(
7474
done,
7575
lowerMinorVersion,
@@ -79,24 +79,24 @@ describe('NodeVersionValidator', function () {
7979
});
8080

8181
function requiredNodeVersionWithDiff(majorDiff, minorDiff, patchDiff) {
82-
var matches = REQUIRED_NODE_JS_VERSION.match(/^v(\d+)\.(\d+)\.(\d+)/);
83-
var major = Math.max(parseInt(matches[1], 10) + majorDiff, 0);
84-
var minor = Math.max(parseInt(matches[2], 10) + minorDiff, 0);
85-
var patch = Math.max(parseInt(matches[3], 10) + patchDiff, 0);
82+
const matches = REQUIRED_NODE_JS_VERSION.match(/^v(\d+)\.(\d+)\.(\d+)/);
83+
const major = Math.max(parseInt(matches[1], 10) + majorDiff, 0);
84+
const minor = Math.max(parseInt(matches[2], 10) + minorDiff, 0);
85+
const patch = Math.max(parseInt(matches[3], 10) + patchDiff, 0);
8686

8787
return `v${major}.${minor}.${patch}`;
8888
}
8989

9090
function testValidateNodeVersion(done, versionToTest, expectError = false) {
91-
var processVersionOverwrite = `Object.defineProperty(process, 'version', { value: '${versionToTest}', writable: true });`;
92-
var command = `node -e "${processVersionOverwrite}require('./node_version_validator.js')"`;
91+
const processVersionOverwrite = `Object.defineProperty(process, 'version', { value: '${versionToTest}', writable: true });`;
92+
const command = `node -e "${processVersionOverwrite}require('./node_version_validator.js')"`;
9393

9494
exec(command, { cwd: __dirname }, function (error, _stdout, stderr) {
9595
expect(stderr).toBeDefined();
9696
if (expectError) {
9797
expect(error.code).toBe(1);
9898

99-
var speficicErrorMessage =
99+
const speficicErrorMessage =
100100
`OpenSearch Dashboards was built with ${REQUIRED_NODE_JS_VERSION} and does not support the current Node.js version ${versionToTest}. ` +
101101
`Please use Node.js ${REQUIRED_NODE_JS_VERSION} or a higher patch version.\n`;
102102

src/setup_node_env/root/force.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* under the License.
2929
*/
3030

31-
var forceRoot = require('./force');
31+
const forceRoot = require('./force');
3232

3333
describe('forceRoot', function () {
3434
it('with flag', function () {
@@ -40,7 +40,7 @@ describe('forceRoot', function () {
4040
});
4141

4242
test('remove argument', function () {
43-
var args = ['--allow-root', 'foo'];
43+
const args = ['--allow-root', 'foo'];
4444
forceRoot(args);
4545
expect(args.includes('--allow-root')).toBeFalsy();
4646
});

src/setup_node_env/root/is_root.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* under the License.
2929
*/
3030

31-
var isRoot = require('./is_root');
31+
const isRoot = require('./is_root');
3232

3333
describe('isRoot', function () {
3434
test('0 is root', function () {

0 commit comments

Comments
 (0)