-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AG-17519 improve logMessage helper and update tests
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-17519 to release/v1.8 Squashed commit of the following: commit f54bbcc Author: Stanislav A <[email protected]> Date: Wed Dec 28 15:52:35 2022 +0300 tweak prevent-xhr test commit 4060687 Author: Stanislav A <[email protected]> Date: Tue Dec 27 19:54:06 2022 +0300 improve helper tests commit 855ce89 Author: Stanislav A <[email protected]> Date: Tue Dec 27 19:14:57 2022 +0300 fix changelog commit 7054753 Author: Stanislav A <[email protected]> Date: Tue Dec 27 18:48:09 2022 +0300 remove max-len from tests commit f93dc21 Author: Stanislav A <[email protected]> Date: Tue Dec 27 18:42:29 2022 +0300 improve naming commit 21da001 Author: Stanislav A <[email protected]> Date: Tue Dec 27 18:30:38 2022 +0300 update tests commit 0903fb6 Author: Stanislav A <[email protected]> Date: Tue Dec 27 18:10:55 2022 +0300 improve helper and add tests commit 6e3dc40 Author: Stanislav A <[email protected]> Date: Tue Dec 27 17:21:56 2022 +0300 improve naming commit d4aa78e Author: Stanislav A <[email protected]> Date: Tue Dec 27 16:04:39 2022 +0300 update CHANGELOG commit 8342527 Author: Stanislav A <[email protected]> Date: Tue Dec 27 16:00:11 2022 +0300 improve logMessage helper and update tests
- Loading branch information
1 parent
1caed03
commit b2624bf
Showing
23 changed files
with
161 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-disable no-console */ | ||
import { | ||
logMessage, | ||
} from '../../src/helpers'; | ||
|
||
const { test, module } = QUnit; | ||
const name = 'scriptlets-redirects helpers'; | ||
const nativeConsole = console.log; | ||
|
||
const afterEach = () => { | ||
console.log = nativeConsole; | ||
}; | ||
|
||
module(name, { afterEach }); | ||
|
||
const RULE_TEXT = 'example.org#%#//scriptlet(\'set-cookie\', \'name\', \'value\')'; | ||
const SCRIPTLET_NAME = 'set-cookie'; | ||
const MESSAGE = 'arbitrary text message'; | ||
const MESSAGE_EXTENSION = '; cannot apply rule: #%#//scriptlet(\'set-cookie\', \'name\', \'value\')'; | ||
|
||
test('Logs message conditionally', async (assert) => { | ||
// eslint-disable-next-line no-console | ||
console.log = function log(input) { | ||
if (input.indexOf('trace') > -1) { | ||
return; | ||
} | ||
assert.strictEqual( | ||
input, | ||
`${SCRIPTLET_NAME}: ${MESSAGE}${MESSAGE_EXTENSION}`, | ||
'message logged correctly', | ||
); | ||
}; | ||
|
||
assert.expect(2); | ||
|
||
// Log forced message | ||
let forced = true; | ||
let source = { | ||
name: SCRIPTLET_NAME, | ||
ruleText: RULE_TEXT, | ||
verbose: false, | ||
}; | ||
logMessage(source, MESSAGE, forced); | ||
|
||
// Log message on verbose | ||
forced = false; | ||
source = { | ||
name: SCRIPTLET_NAME, | ||
ruleText: RULE_TEXT, | ||
verbose: true, | ||
}; | ||
logMessage(source, MESSAGE, forced); | ||
|
||
// Message should not be logged this time, thus expected 2 asserts | ||
forced = false; | ||
source = { | ||
name: SCRIPTLET_NAME, | ||
ruleText: RULE_TEXT, | ||
verbose: false, | ||
}; | ||
logMessage(source, MESSAGE, forced); | ||
}); | ||
|
||
test('Logs message without ruleText', async (assert) => { | ||
// eslint-disable-next-line no-console | ||
console.log = function log(input) { | ||
if (input.indexOf('trace') > -1) { | ||
return; | ||
} | ||
assert.strictEqual( | ||
input, | ||
`${SCRIPTLET_NAME}: ${MESSAGE}`, | ||
'message logged correctly', | ||
); | ||
}; | ||
|
||
const FORCED = true; | ||
const source = { | ||
name: SCRIPTLET_NAME, | ||
verbose: false, | ||
}; | ||
logMessage(source, MESSAGE, FORCED); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.