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

Move android matchers to generated code #745

Merged
merged 2 commits into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
};