Skip to content

Commit

Permalink
AG-30369 add specs for examples
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-30369 to master

Squashed commit of the following:

commit e5bc36c
Merge: e079e90 d992758
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Fri Apr 5 12:55:27 2024 +0300

    Merge branch 'master' into fix/AG-30369

commit e079e90
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Fri Apr 5 12:28:35 2024 +0300

    AG-30369 apply review notes

commit 289cb2c
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Thu Apr 4 18:33:10 2024 +0300

    AG-30369 comment tests

commit ec276e8
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Thu Apr 4 18:28:39 2024 +0300

    AG-30369 add specs for examples
  • Loading branch information
maximtop committed Apr 5, 2024
1 parent d992758 commit eb848a4
Show file tree
Hide file tree
Showing 19 changed files with 776 additions and 252 deletions.
8 changes: 7 additions & 1 deletion bamboo-specs/bamboo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@
!include 'logger-test.yaml'

---
!include 'adguard-api-example-tests.yaml'
!include 'examples-adguard-api-tests.yaml'

---
!include 'examples-tswebextension-mv2-tests.yaml'

---
!include 'examples-tswebextension-mv3-tests.yaml'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
plan:
project-key: AJL
key: AGAPIEXTEST
name: adguard-api-example - tests
name: examples-adguard-api - tests
variables:
dockerContainer: adguard/node-ssh:18.19--0

Expand Down
99 changes: 99 additions & 0 deletions bamboo-specs/examples-tswebextension-mv2-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
version: 2
plan:
project-key: AJL
key: AGTSWEBEXTMVTWOTEST
name: examples-tswebextension-mv2 - tests
variables:
dockerContainer: adguard/node-ssh:18.19--0

stages:
- Test:
manual: false
final: false
jobs:
- Test

Test:
key: TEST
docker:
image: "${bamboo.dockerContainer}"
volumes:
${system.PNPM_DIR}: "${bamboo.cachePnpm}"
tasks:
- checkout:
force-clean-build: 'true'
- script:
interpreter: SHELL
scripts:
- |-
set -e
set -x
# Fix mixed logs
exec 2>&1
ls -alt
# Set cache directory
pnpm config set store-dir ${bamboo.cachePnpm}
# Install deps
pnpm install
# Lint
pnpm --filter tswebextension-mv2 lint
# Build, and after that test
npx lerna run build --scope tswebextension-mv2 --include-dependencies
# # Test
# # TODO: fail if tests are not passing
# pnpm --filter tswebextension-mv2 test
# TODO add artifacts
# artifacts:
# - name: extension.zip
# location: packages/examples/adguard-api/build
# pattern: extension.zip
# shared: true
# required: false
final-tasks:
- script:
interpreter: SHELL
scripts:
- |-
set -x
set -e
# Fix mixed logs
exec 2>&1
ls -la
echo "Size before cleanup:" && du -h | tail -n 1
pnpm clean
echo "Size after cleanup:" && du -h | tail -n 1
requirements:
- adg-docker: 'true'

branches:
create: for-pull-request
delete:
after-deleted-days: '1'
after-inactive-days: '5'
link-to-jira: 'true'

notifications:
- events:
- plan-status-changed
recipients:
- webhook:
name: Build webhook
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo

labels: [ ]

other:
concurrent-build-plugin: system-default
100 changes: 100 additions & 0 deletions bamboo-specs/examples-tswebextension-mv3-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
version: 2
plan:
project-key: AJL
key: AGTSWEBEXTMVTHREETEST
name: examples-tswebextension-mv3 - tests
variables:
dockerContainer: adguard/node-ssh:18.19--0

stages:
- Test:
manual: false
final: false
jobs:
- Test

Test:
key: TEST
docker:
image: "${bamboo.dockerContainer}"
volumes:
${system.PNPM_DIR}: "${bamboo.cachePnpm}"
tasks:
- checkout:
force-clean-build: 'true'
- script:
interpreter: SHELL
scripts:
- |-
set -e
set -x
# Fix mixed logs
exec 2>&1
ls -alt
# Set cache directory
pnpm config set store-dir ${bamboo.cachePnpm}
# Install deps
pnpm install
# Lint
pnpm --filter tswebextension-mv3 lint
# Build
npx lerna run build --scope tswebextension-mv3 --include-dependencies
# # Test
# # Should be run after build, since test requires build
# # TODO fail if tests are not passing
# pnpm --filter tswebextension-mv3 test
# TODO add artifacts for testing
# artifacts:
# - name: extension.zip
# location: packages/examples/adguard-api/build
# pattern: extension.zip
# shared: true
# required: false
final-tasks:
- script:
interpreter: SHELL
scripts:
- |-
set -x
set -e
# Fix mixed logs
exec 2>&1
ls -la
echo "Size before cleanup:" && du -h | tail -n 1
pnpm clean
echo "Size after cleanup:" && du -h | tail -n 1
requirements:
- adg-docker: 'true'

branches:
create: for-pull-request
delete:
after-deleted-days: '1'
after-inactive-days: '5'
link-to-jira: 'true'

notifications:
- events:
- plan-status-changed
recipients:
- webhook:
name: Build webhook
url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo

labels: [ ]

other:
concurrent-build-plugin: system-default
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import browser, { Events } from 'webextension-polyfill';
import { TsWebExtension, ConfigurationMV2, MESSAGE_HANDLER_NAME } from '@adguard/tswebextension';
import {
type ConfigurationMV2,
MESSAGE_HANDLER_NAME,
createTsWebExtension,
} from '@adguard/tswebextension';

import { MessageTypes } from '../common/message-types';
import { BuildOutput } from '../../../constants';

const tsWebExtension = new TsWebExtension('war');
const tsWebExtension = createTsWebExtension('war');

/*
* Need for access tsWebExtension instance form browser auto test tool
*/

declare global {
interface Window {
tsWebExtension: TsWebExtension;
tsWebExtension: typeof tsWebExtension;
}
}

Expand Down Expand Up @@ -47,6 +50,8 @@ const defaultConfig: ConfigurationMV2 = {
},
};

tsWebExtension.initStorage();

tsWebExtension.start(defaultConfig);

tsWebExtension.onFilteringLogEvent.subscribe(console.log);
Expand All @@ -55,7 +60,9 @@ tsWebExtension.onAssistantCreateRule.subscribe((rule) => console.log(`assistant

const tsWebExtensionMessageHandler = tsWebExtension.getMessageHandler();

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(browser.runtime.onMessage as Events.Event<(...args: any[]) => void>).addListener((message, sender, sendResponse) => {

if (message.handlerName === MESSAGE_HANDLER_NAME) {
return tsWebExtensionMessageHandler(message, sender);
}
Expand Down
38 changes: 19 additions & 19 deletions packages/examples/tswebextension-mv2/extension/src/popup/app.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import React, { useEffect, useState } from 'react'
import { Formik } from 'formik'
import React, { useEffect, useState } from 'react';
import { Formik } from 'formik';

import { MessageTypes } from '../common/message-types'
import { MessageTypes } from '../common/message-types';

import './app.css'
import './app.css';

const rulesArrayToText = (arr: string[]): string => arr.join('\n')
const rulesTextToArray = (text: string): string[] => text.trim().split('\n').filter(el => el !== '')
const rulesArrayToText = (arr: string[]): string => arr.join('\n');
const rulesTextToArray = (text: string): string[] => text.trim().split('\n').filter(el => el !== '');

export function App() {
const [formValue, setFormValue] = useState({
userrules: "",
allowlist: "",
})
userrules: '',
allowlist: '',
});

useEffect(() => {
chrome.runtime.sendMessage({
type: MessageTypes.GET_CONFIG,
}, (response) => {
if(response?.payload){
const { userrules, allowlist } = response.payload
if (response?.payload) {
const { userrules, allowlist } = response.payload;

setFormValue({
userrules: rulesArrayToText(userrules),
allowlist: rulesArrayToText(allowlist),
})
});
}
})
});
}, []);

const handleOpenAssistant = () => {
chrome.runtime.sendMessage({
type: MessageTypes.OPEN_ASSISTANT
type: MessageTypes.OPEN_ASSISTANT,
});

return false;
};

const handleCloseAssistant = () => {
chrome.runtime.sendMessage({
type: MessageTypes.CLOSE_ASSISTANT
type: MessageTypes.CLOSE_ASSISTANT,
});

return false;
Expand All @@ -53,15 +53,15 @@ export function App() {
const payload = {
userrules: rulesTextToArray(values.userrules),
allowlist: rulesTextToArray(values.allowlist),
}
};
chrome.runtime.sendMessage({
type: MessageTypes.SET_CONFIG,
payload,
}, (response) => {
if (response?.type === MessageTypes.SET_CONFIG_FAIL) {
alert(response?.payload)
alert(response?.payload);
}
})
});
}}
>
{({
Expand Down Expand Up @@ -98,5 +98,5 @@ export function App() {
</form>
)}
</Formik>
)
);
}
10 changes: 7 additions & 3 deletions packages/examples/tswebextension-mv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:ff": "BROWSER=firefox node -r @swc-node/register ./scripts/build/index.ts",
"run:ff": "node -r @swc-node/register ./scripts/launchFirefoxExtension.ts",
"test": "node -r @swc-node/register ./scripts/browser-test/index.ts",
"lint": "eslint 'extension/**/*.ts' 'scripts/**/*.ts'",
"lint": "eslint 'extension/**/*.ts' 'scripts/**/*.ts' && tsc --noEmit",
"tswebextension": "tswebextension"
},
"dependencies": {
Expand All @@ -24,15 +24,19 @@
"devDependencies": {
"@swc-node/register": "^1.6.6",
"@swc/core": "^1.3.76",
"@types/chrome": "^0.0.263",
"@types/react": "^17.0.34",
"@types/react-dom": "^17.0.11",
"@types/webextension-polyfill": "^0.10.7",
"@typescript-eslint/eslint-plugin": "^7.5.0",
"@typescript-eslint/parser": "^7.5.0",
"axios": "^0.24.0",
"chalk": "4.1.2",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^10.0.0",
"css-loader": "^6.5.1",
"eslint": "^8.6.0",
"eslint-config-airbnb-typescript": "^16.1.0",
"eslint": "^8.56.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-plugin-import": "^2.25.4",
"html-webpack-plugin": "^5.5.0",
"jsdom": "^18.1.1",
Expand Down

0 comments on commit eb848a4

Please sign in to comment.