11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif ((!common.hasCrypto) || (!common.hasIntl)) { 51cb0ef41Sopenharmony_ci common.skip('ESLint tests require crypto and Intl'); 61cb0ef41Sopenharmony_ci} 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cicommon.skipIfEslintMissing(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst RuleTester = require('../../tools/node_modules/eslint').RuleTester; 111cb0ef41Sopenharmony_ciconst rule = require('../../tools/eslint-rules/prefer-assert-iferror'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinew RuleTester().run('prefer-assert-iferror', rule, { 141cb0ef41Sopenharmony_ci valid: [ 151cb0ef41Sopenharmony_ci 'assert.ifError(err);', 161cb0ef41Sopenharmony_ci 'if (err) throw somethingElse;', 171cb0ef41Sopenharmony_ci 'throw err;', 181cb0ef41Sopenharmony_ci 'if (err) { throw somethingElse; }', 191cb0ef41Sopenharmony_ci ], 201cb0ef41Sopenharmony_ci invalid: [ 211cb0ef41Sopenharmony_ci { 221cb0ef41Sopenharmony_ci code: 'require("assert");\n' + 231cb0ef41Sopenharmony_ci 'if (err) throw err;', 241cb0ef41Sopenharmony_ci errors: [{ message: 'Use assert.ifError(err) instead.' }], 251cb0ef41Sopenharmony_ci output: 'require("assert");\n' + 261cb0ef41Sopenharmony_ci 'assert.ifError(err);' 271cb0ef41Sopenharmony_ci }, 281cb0ef41Sopenharmony_ci { 291cb0ef41Sopenharmony_ci code: 'require("assert");\n' + 301cb0ef41Sopenharmony_ci 'if (error) { throw error; }', 311cb0ef41Sopenharmony_ci errors: [{ message: 'Use assert.ifError(error) instead.' }], 321cb0ef41Sopenharmony_ci output: 'require("assert");\n' + 331cb0ef41Sopenharmony_ci 'assert.ifError(error);' 341cb0ef41Sopenharmony_ci }, 351cb0ef41Sopenharmony_ci ] 361cb0ef41Sopenharmony_ci}); 37