Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove callbacks #11

Merged
merged 51 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
571d5ac
Disable actions
Maaaartin Oct 15, 2023
ab753a1
Start removing callback overloads
Maaaartin Oct 15, 2023
b9fff12
Remove callback overloads
Maaaartin Oct 15, 2023
082386f
Disable workflows
Maaaartin Oct 16, 2023
4f78c05
Remove callback overloads
Maaaartin Oct 16, 2023
8d35bc7
Remove callback from install method
Maaaartin Oct 17, 2023
54c3a7f
Remove rest of callback overloads
Maaaartin Oct 18, 2023
35628bc
Resolve TS errors
Maaaartin Oct 18, 2023
0edeb39
Remove unused stuff
Maaaartin Oct 18, 2023
fc5e836
Add public
Maaaartin Oct 18, 2023
e9379bd
Remove callback tests
Maaaartin Oct 20, 2023
5f2cb4d
Remove callback tests
Maaaartin Oct 21, 2023
09349e0
Fix install method
Maaaartin Oct 21, 2023
c0696f6
Fix pullFile method
Maaaartin Oct 21, 2023
dd2c31e
Enable actions
Maaaartin Oct 21, 2023
1a70703
Refactor event unregistering
Maaaartin Oct 31, 2023
1ee60a3
Remove old event unregister
Maaaartin Oct 31, 2023
b6f00a5
Refactor read
Maaaartin Feb 14, 2024
5de575c
Refactor let
Maaaartin Feb 15, 2024
2b9d298
Remove default value
Maaaartin Feb 15, 2024
85ce384
Refactor to async/await
Maaaartin Feb 21, 2024
0938a2a
Refactor promise chains
Maaaartin Feb 21, 2024
14fcbdc
Remove redundant date parse
Maaaartin Feb 21, 2024
9289f67
Revert "Refactor to async/await"
Maaaartin May 15, 2024
f4c4523
Fix kill method
Maaaartin May 15, 2024
86ce027
Remove redundant union
Maaaartin May 16, 2024
b26ebc3
Use existing Device instances
Maaaartin May 17, 2024
5f68554
Remove moment
Maaaartin May 18, 2024
2a5491b
Update dependencies and node
Maaaartin May 18, 2024
f5da478
Use correct eslint version
Maaaartin May 18, 2024
917a8d7
Use 18.18.0 node in workflows
Maaaartin May 18, 2024
c25f35d
Use UTC time, dynamically format time in test
Maaaartin May 18, 2024
a1d7db3
Remove redundant condition
Maaaartin May 19, 2024
279e70e
Use local address instead of localhost
Maaaartin May 19, 2024
fc6b2ce
Change to once
Maaaartin May 20, 2024
c368577
Fix read devices when data is corrupt
Maaaartin Jun 21, 2024
5d1e4a1
Merge branch 'remove_callbacks' of github.com:Maaaartin/adb-ts into r…
Maaaartin Jun 21, 2024
b13d515
Add test case for corrupt device data
Maaaartin Jun 21, 2024
5a47764
Add test for tracker
Maaaartin Jun 21, 2024
6019570
Abstract package commands
Maaaartin Jun 23, 2024
5b06845
Add back support for node 16
Maaaartin Jun 24, 2024
0a449cb
Add password to gihub action
Maaaartin Jun 24, 2024
112fbbb
Remove client property on emitted object
Maaaartin Jun 24, 2024
886a149
Remove log
Maaaartin Jun 24, 2024
32377b3
Add tests for node versions
Maaaartin Jul 6, 2024
8094524
Rename action
Maaaartin Jul 6, 2024
75a61a8
Change node version
Maaaartin Jul 6, 2024
293a85f
Rename job
Maaaartin Jul 6, 2024
dc15742
Remove TODO
Maaaartin Jul 6, 2024
c5d5b88
Add change log notes
Maaaartin Jul 6, 2024
946e7c6
Add change log
Maaaartin Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Node, NPM and Yarn
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: 'https://registry.npmjs.org'

- name: Install modules
Expand All @@ -37,7 +37,9 @@ jobs:
yarn test

- name: Git config
run: git config --global user.email "[email protected]" && git config --global user.name "bot"
run: |
git config --global user.email "[email protected]" && git config --global user.name "bot"
password=${{ secrets.GITHUB_TOKEN }}

- name: Apply version major
if: contains(github.event.pull_request.labels.*.name, 'major')
Expand Down
43 changes: 36 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build and test
on: push
jobs:
test:
name: Test and lint
build:
name: Build and lint
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -11,7 +11,7 @@ jobs:
- name: Install Node, NPM and Yarn
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Install modules
run: |
Expand All @@ -24,10 +24,39 @@ jobs:
- name: Lint
run: |
yarn lint

- name: Test
run: |
yarn test
- name: Test generate docs
run: |
yarn docs
- name: Upload lib Artifacts
uses: actions/upload-artifact@v2
with:
name: lib
path: ./lib
test-versions:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 17, 18, 19, 20, 21]
steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Setup Yarn
run: |
npm install -g yarn
- name: Install packages
run: |
yarn install --frozen-lockfile --ignore-engines

- name: Download lib Artifacts
uses: actions/download-artifact@v2
with:
name: lib
path: ./lib
- name: Test
run: yarn test
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ dist

# TernJS port file
.tern-port
.DS_Store

# Custom
lib
script.ts
script.*
*.apk
docs/
.DS_Store
6 changes: 6 additions & 0 deletions README_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ adb.listDevices((devices) => {
console.log(devices);
});
```

## Changes from V5

- `time` option in `touch` method is converted to UTC time.
- Tracker `change` event emits the same instance of the device instead of creating a new device object every time.
- `install` and `uninstall` commands will fail if any other response than `Success` is received. Until V5 the promise could have resolved even when the operation was not successful.
17 changes: 0 additions & 17 deletions __tests__/adbClient/connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AdbMock } from '../../mockery/mockAdbServer';
import { Client } from '../../lib/client';
import { promisify } from 'util';

describe('Connect', () => {
it('Connect to default port', async () => {
Expand Down Expand Up @@ -72,20 +71,4 @@ describe('Connect', () => {
await adbMock.end();
}
});

it('Connect callback overload', async () => {
const adbMock = new AdbMock([
{ cmd: 'host:connect:127.0.0.1:4444', res: 'connected to' }
]);
try {
const port = await adbMock.start();
const adb = new Client({ noAutoStart: true, port });
const result = await promisify<string>((cb) => {
adb.connect('127.0.0.1', 4444, cb);
})();
expect(result).toBe('127.0.0.1:4444');
} finally {
await adbMock.end();
}
});
});
30 changes: 2 additions & 28 deletions __tests__/adbClient/constructorAndStartServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Client constructor tests', () => {
const client = new Client();
expect(client['options']).toEqual({
port: 5037,
host: 'localhost',
host: '127.0.0.1',
bin: 'adb',
noAutoStart: false
});
Expand All @@ -16,7 +16,7 @@ describe('Client constructor tests', () => {
const client = new Client({ bin: undefined, port: 5036 });
expect(client['options']).toEqual({
port: 5036,
host: 'localhost',
host: '127.0.0.1',
bin: 'adb',
noAutoStart: false
});
Expand All @@ -29,30 +29,4 @@ describe('Start server tests', () => {
const client = new Client();
await expect(client.startServer()).resolves.toBeUndefined();
});

it('Start adb server error', async () => {
try {
mockExec(new Error('message'));
const client = new Client();
await client.startServer();
} catch (e: unknown) {
expect(e).toEqual(new Error('message'));
}
});

it('Start adb server callback overload', () => {
mockExec(null);
const client = new Client();
client.startServer((err) => {
expect(err).toBeNull();
});
});

it('Start adb server callback overload error', () => {
mockExec(new Error('message'));
const client = new Client();
client.startServer((err) => {
expect(err).toBeInstanceOf(Error);
});
});
});
58 changes: 0 additions & 58 deletions __tests__/adbClient/cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import crypto from 'crypto';
import { UnexpectedDataError } from '../../lib/util';
import { Client } from '../../lib/client';
import { AdbMock } from '../../mockery/mockAdbServer';
import { promisify } from 'util';

beforeAll(() => {
jest.spyOn(crypto, 'randomUUID').mockImplementation(() => {
Expand Down Expand Up @@ -30,27 +29,6 @@ describe('Cp OKAY tests', () => {
}
});

it('Should execute callback overload without options', async () => {
const adbMock = new AdbMock([
{ cmd: 'host:transport:serial', res: null, rawRes: true },
{
cmd: `shell:(cp /file /other) || echo '1-2-3-4-5'`,
res: null,
rawRes: true
}
]);
try {
const port = await adbMock.start();
const adb = new Client({ noAutoStart: true, port });
const result = await promisify<void>((cb) =>
adb.cp('serial', '/file', '/other', cb)
)();
expect(result).toBeUndefined();
} finally {
await adbMock.end();
}
});

it('Should execute with simple parameters without archive', async () => {
const adbMock = new AdbMock([
{ cmd: 'host:transport:serial', res: null, rawRes: true },
Expand Down Expand Up @@ -172,42 +150,6 @@ describe('Cp OKAY tests', () => {
await adbMock.end();
}
});

it('Should execute callback overload with preserve option with all', async () => {
const adbMock = new AdbMock([
{ cmd: 'host:transport:serial', res: null, rawRes: true },
{
cmd: `shell:(cp --preserve=a /file /other) || echo '1-2-3-4-5'`,
res: 'data',
rawRes: true
}
]);
try {
const port = await adbMock.start();
const adb = new Client({ noAutoStart: true, port });
const result = await promisify<void>((cb) =>
adb.cp(
'serial',
'/file',
'/other',
{
preserve: {
all: true,
mode: true,
ownership: true,
timestamps: true,
context: true,
xattr: true
}
},
cb
)
)();
expect(result).toBeUndefined();
} finally {
await adbMock.end();
}
});
});

describe('Cp FAIL tests', () => {
Expand Down
20 changes: 0 additions & 20 deletions __tests__/adbClient/disconnect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AdbMock } from '../../mockery/mockAdbServer';
import { Client } from '../../lib/client';
import { promisify } from 'util';

describe('Disconnect', () => {
it('Disconnect from default port', async () => {
Expand Down Expand Up @@ -91,23 +90,4 @@ describe('Disconnect', () => {
await adbMock.end();
}
});

it('Connect callback overload', async () => {
const adbMock = new AdbMock([
{
cmd: 'host:disconnect:127.0.0.1:4444',
res: 'disconnected'
}
]);
try {
const port = await adbMock.start();
const adb = new Client({ noAutoStart: true, port });
const result = await promisify<string>((cb) => {
adb.disconnect('127.0.0.1', 4444, cb);
})();
expect(result).toBe('127.0.0.1:4444');
} finally {
await adbMock.end();
}
});
});
Loading
Loading