Skip to content

Commit e03cc6e

Browse files
DanielMSchmidtrotemmiz
authored andcommitted
Android: Move matchers to generated code (#745)
* move android matchers to generated code Closes #725 * apply prettier styles to code generation
1 parent 0294525 commit e03cc6e

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

detox/src/android/matcher.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const invoke = require('../invoke');
22
const DetoxMatcherApi = require('./espressoapi/DetoxMatcher');
33

4-
const DetoxMatcher = 'com.wix.detox.espresso.DetoxMatcher';
5-
64
class Matcher {
75
withAncestor(matcher) {
86
this._call = invoke.callDirectly(DetoxMatcherApi.matcherWithAncestor(this, matcher));
@@ -45,8 +43,7 @@ class Matcher {
4543
class LabelMatcher extends Matcher {
4644
constructor(value) {
4745
super();
48-
if (typeof value !== 'string') throw new Error(`LabelMatcher ctor argument must be a string, got ${typeof value}`);
49-
this._call = invoke.call(invoke.Android.Class(DetoxMatcher), 'matcherForContentDescription', value);
46+
this._call = invoke.callDirectly(DetoxMatcherApi.matcherForContentDescription(value));
5047
}
5148
}
5249

generation/README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ To correlate changes to the generation with changes in the generated code, pleas
99

1010
## Development
1111

12-
* `npm install`
13-
* `npm run build` builds every file specified in the `index.js`
14-
* `npm test`
12+
- `npm install`
13+
- `npm run build` builds every file specified in the `index.js`
14+
- `npm test`
1515

1616
## Testing
1717

18-
* We test with integration level tests by having a fixture Objective-C file which we generate and import before the tests.
19-
* We only add unit tests for code that is used in production, e.g. helper functions.
20-
* We then test against this file to ensure that the code generation result works with the specified interface.
21-
* We decided to base our tests around snapshot tests with the goal to spot mistakes in the return values of the functions without over-specification.
22-
* If you add functionality that affects the API surface of detox, please also make sure to include [End to End tests for it](../detox/test/e2e).
18+
- We test with integration level tests by having a fixture Objective-C file which we generate and import before the tests.
19+
- We only add unit tests for code that is used in production, e.g. helper functions.
20+
- We then test against this file to ensure that the code generation result works with the specified interface.
21+
- We decided to base our tests around snapshot tests with the goal to spot mistakes in the return values of the functions without over-specification.
22+
- If you add functionality that affects the API surface of detox, please also make sure to include [End to End tests for it](../detox/test/e2e).
2323

2424
## Resources
2525

2626
Parsing, ASTs, and code generation are hard topics but don't worry; we got your back.
2727
Here are some resources that might come in handy:
2828

29-
* [astexplorer](https://astexplorer.net): Allows you to understand Abstract Syntax Trees by showing you code and the resulting AST side-by-side.
30-
* [Babel Handbook](https://github.com/thejameskyle/babel-handbook):
31-
* [babel-types](https://github.com/babel/babel/tree/master/packages/babel-types): A builder library for ASTs.
32-
* [babel-template](https://github.com/babel/babel/tree/master/packages/babel-template): A useful tool we do not use yet for generating bigger ASTs with less code by the usage of string interpolation.
33-
* [regex101](https://regex101.com): You might need to extract parts of a string; This tool helps you to quickly build the right Regular Expression for the job.
29+
- [astexplorer](https://astexplorer.net): Allows you to understand Abstract Syntax Trees by showing you code and the resulting AST side-by-side.
30+
- [Babel Handbook](https://github.com/thejameskyle/babel-handbook):
31+
- [babel-types](https://github.com/babel/babel/tree/master/packages/babel-types): A builder library for ASTs.
32+
- [babel-template](https://github.com/babel/babel/tree/master/packages/babel-template): A useful tool we do not use yet for generating bigger ASTs with less code by the usage of string interpolation.
33+
- [regex101](https://regex101.com): You might need to extract parts of a string; This tool helps you to quickly build the right Regular Expression for the job.

generation/utils/downloadFile.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const uuidv4 = require('uuid/v4');
44
const downloadFileSync = require('download-file-sync');
55

66
module.exports = function downloadJava(url) {
7-
const tmpDir = os.tmpdir();
8-
const fileContent = downloadFileSync(url);
9-
10-
const result = Buffer.from(fileContent, 'base64').toString('ascii');
11-
const filePath = tmpDir + `/${uuidv4()}.java`;
12-
fs.writeFileSync(filePath, result);
13-
return filePath;
14-
}
7+
const tmpDir = os.tmpdir();
8+
const fileContent = downloadFileSync(url);
9+
10+
const result = Buffer.from(fileContent, 'base64').toString('ascii');
11+
const filePath = tmpDir + `/${uuidv4()}.java`;
12+
fs.writeFileSync(filePath, result);
13+
return filePath;
14+
};

0 commit comments

Comments
 (0)