Skip to content

Commit

Permalink
Android: Move matchers to generated code (wix#745)
Browse files Browse the repository at this point in the history
* move android matchers to generated code

Closes wix#725

* apply prettier styles to code generation
  • Loading branch information
DanielMSchmidt authored and rotemmiz committed Jun 10, 2018
1 parent 0294525 commit e03cc6e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
5 changes: 1 addition & 4 deletions detox/src/android/matcher.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const invoke = require('../invoke');
const DetoxMatcherApi = require('./espressoapi/DetoxMatcher');

const DetoxMatcher = 'com.wix.detox.espresso.DetoxMatcher';

class Matcher {
withAncestor(matcher) {
this._call = invoke.callDirectly(DetoxMatcherApi.matcherWithAncestor(this, matcher));
Expand Down Expand Up @@ -45,8 +43,7 @@ class Matcher {
class LabelMatcher extends Matcher {
constructor(value) {
super();
if (typeof value !== 'string') throw new Error(`LabelMatcher ctor argument must be a string, got ${typeof value}`);
this._call = invoke.call(invoke.Android.Class(DetoxMatcher), 'matcherForContentDescription', value);
this._call = invoke.callDirectly(DetoxMatcherApi.matcherForContentDescription(value));
}
}

Expand Down
26 changes: 13 additions & 13 deletions generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ To correlate changes to the generation with changes in the generated code, pleas

## Development

* `npm install`
* `npm run build` builds every file specified in the `index.js`
* `npm test`
- `npm install`
- `npm run build` builds every file specified in the `index.js`
- `npm test`

## Testing

* We test with integration level tests by having a fixture Objective-C file which we generate and import before the tests.
* We only add unit tests for code that is used in production, e.g. helper functions.
* We then test against this file to ensure that the code generation result works with the specified interface.
* 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.
* 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).
- We test with integration level tests by having a fixture Objective-C file which we generate and import before the tests.
- We only add unit tests for code that is used in production, e.g. helper functions.
- We then test against this file to ensure that the code generation result works with the specified interface.
- 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.
- 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).

## Resources

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

* [astexplorer](https://astexplorer.net): Allows you to understand Abstract Syntax Trees by showing you code and the resulting AST side-by-side.
* [Babel Handbook](https://github.com/thejameskyle/babel-handbook):
* [babel-types](https://github.com/babel/babel/tree/master/packages/babel-types): A builder library for ASTs.
* [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.
* [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.
- [astexplorer](https://astexplorer.net): Allows you to understand Abstract Syntax Trees by showing you code and the resulting AST side-by-side.
- [Babel Handbook](https://github.com/thejameskyle/babel-handbook):
- [babel-types](https://github.com/babel/babel/tree/master/packages/babel-types): A builder library for ASTs.
- [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.
- [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.
16 changes: 8 additions & 8 deletions generation/utils/downloadFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const uuidv4 = require('uuid/v4');
const downloadFileSync = require('download-file-sync');

module.exports = function downloadJava(url) {
const tmpDir = os.tmpdir();
const fileContent = downloadFileSync(url);
const result = Buffer.from(fileContent, 'base64').toString('ascii');
const filePath = tmpDir + `/${uuidv4()}.java`;
fs.writeFileSync(filePath, result);
return filePath;
}
const tmpDir = os.tmpdir();
const fileContent = downloadFileSync(url);

const result = Buffer.from(fileContent, 'base64').toString('ascii');
const filePath = tmpDir + `/${uuidv4()}.java`;
fs.writeFileSync(filePath, result);
return filePath;
};

0 comments on commit e03cc6e

Please sign in to comment.