Skip to content

Commit

Permalink
AG-25746: simplify work with constants in mv3 example
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from feature/AG-25746 to master

Squashed commit of the following:

commit 605c937
Author: Dmitriy Seregin <[email protected]>
Date:   Mon Sep 11 13:46:45 2023 +0300

    AG-25746: simplify work with constants in mv3 example
  • Loading branch information
105th committed Sep 11, 2023
1 parent 6567b41 commit ede8ce0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import { Configuration } from '@adguard/tswebextension/mv3';
import { type Configuration } from '@adguard/tswebextension/mv3';
import { DEFAULT_EXTENSION_CONFIG } from '../../../scripts/constants';

/**
* Return default configuration with loaded filters content
* @param filtersDir directory with filters in txt format
* @returns configuration
*/
export const loadDefaultConfig = (): Configuration => {
console.debug('[LOAD DEFAULT CONFIG]: start');
console.debug('[LOAD DEFAULT CONFIG]');

const defaultConfig: Configuration = {
staticFiltersIds: [1, 2, 3, 4, 9, 14],
customFilters: [],
allowlist: [],
trustedDomains: [],
userrules: [],
verbose: false,
filtersPath: 'filters',
ruleSetsPath: 'filters/declarative',
filteringLogEnabled: false,
settings: {
assistantUrl: '',
collectStats: true,
allowlistInverted: false,
allowlistEnabled: false,
documentBlockingPageUrl: chrome.runtime.getURL('pages/document-blocking.html'),
stealthModeEnabled: true,
filteringEnabled: true,
stealth: {
blockChromeClientData: true,
hideReferrer: true,
hideSearchQueries: true,
sendDoNotTrack: true,
blockWebRTC: true,
selfDestructThirdPartyCookies: true,
selfDestructThirdPartyCookiesTime: 3600,
selfDestructFirstPartyCookies: true,
selfDestructFirstPartyCookiesTime: 3600,
},
},
};

console.debug('[LOAD DEFAULT CONFIG]: end');

return defaultConfig;
return DEFAULT_EXTENSION_CONFIG;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { chromium } from 'playwright';

import {
BUILD_PATH,
USER_DATA_PATH,
DEFAULT_EXTENSION_CONFIG,
TESTCASES_BASE_URL,
} from '../constants';
Expand All @@ -19,6 +17,7 @@ import { getTestcases, getRuleText } from './requests';
import { filterCompatibleTestcases } from './testcase';
import { logTestResult, logTestTimeout } from './logger';
import { Product } from './product';
import { BUILD_PATH, USER_DATA_PATH } from '../build/constants';

const TESTS_TIMEOUT_MS = 5 * 1000;
const TESTS_TIMEOUT_CODE = 'tests_timeout';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import path from 'path';

export const BUILD_PATH = path.join(__dirname, '../build');

export const USER_DATA_PATH = path.join(__dirname, '../tmp');
8 changes: 1 addition & 7 deletions packages/examples/tswebextension-mv3/scripts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import path from 'path';

import { Configuration } from '@adguard/tswebextension/mv3';

export const BUILD_PATH = path.join(__dirname, '../build');

export const USER_DATA_PATH = path.join(__dirname, '../tmp');

// TODO: can be used as common for examples/tswebextension-mv2 as well
export const TESTCASES_BASE_URL = 'https://testcases.agrd.dev';

export const TESTCASES_DATA_PATH = '/data.json';

export const DEFAULT_EXTENSION_CONFIG: Configuration = {
staticFiltersIds: [],
staticFiltersIds: [1, 2, 3, 4, 9, 14],
customFilters: [],
allowlist: [],
userrules: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { getFilterName } from '@adguard/tswebextension/mv3/utils';
import axios from 'axios';
import path from 'path';
import { ensureDir } from 'fs-extra';
import { DEFAULT_EXTENSION_CONFIG } from './constants';

const COMMON_FILTERS_DIR = './extension/filters';
const FILTERS_DIR = `${COMMON_FILTERS_DIR}`;
const DEST_RULE_SETS_DIR = `${COMMON_FILTERS_DIR}/declarative`;
const RESOURCES_DIR = '/war/redirects';

const ADGUARD_FILTERS_IDS = [1, 2, 3, 4, 9, 14];
const ADGUARD_FILTERS_IDS = DEFAULT_EXTENSION_CONFIG.staticFiltersIds;

const EXTENSION_FILTERS_SERVER_URL_FORMAT = 'https://filters.adtidy.org/extension/chromium';
const FILTER_DOWNLOAD_URL_FORMAT = `${EXTENSION_FILTERS_SERVER_URL_FORMAT}/filters/%filter.txt`;
Expand Down

0 comments on commit ede8ce0

Please sign in to comment.