Skip to content

Commit

Permalink
Add check for ungenerated code (wix#679)
Browse files Browse the repository at this point in the history
* add check for ungenerated code

* consolidate prettierrc for subprojects

In this step we also changed the config to standards that match
our code styles better.

* ignore package.json with prettier

This file gets rewritten with an npm install, so it leads to
unnecessary changes

* apply prettier styles to code generation

* regenerated adapter code
  • Loading branch information
DanielMSchmidt authored and rotemmiz committed May 17, 2018
1 parent 2153afa commit c6b1b67
Show file tree
Hide file tree
Showing 20 changed files with 496 additions and 615 deletions.
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": false,
"tabWidth": 2,
"printWidth": 140,
"singleQuote": true,
"arrowParens": "always",
"trailingComma": "none"
}
24 changes: 10 additions & 14 deletions detox/src/android/espressoapi/DetoxAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@

function sanitize_android_edge(edge) {
switch (edge) {
case "left":
case 'left':
return 1;
case "right":
case 'right':
return 2;
case "top":
case 'top':
return 3;
case "bottom":
case 'bottom':
return 4;
default:
throw new Error(
`edge must be a 'left'/'right'/'top'/'bottom', got ${edge}`
);
throw new Error(`edge must be a 'left'/'right'/'top'/'bottom', got ${edge}`);
}
}
function sanitize_android_direction(direction) {
switch (direction) {
case "left":
case 'left':
return 1;
case "right":
case 'right':
return 2;
case "up":
case 'up':
return 3;
case "down":
case 'down':
return 4;
default:
throw new Error(
`direction must be a 'left'/'right'/'up'/'down', got ${direction}`
);
throw new Error(`direction must be a 'left'/'right'/'up'/'down', got ${direction}`);
}
}
class DetoxAction {
Expand Down
3 changes: 1 addition & 2 deletions detox/src/android/espressoapi/DetoxMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


function sanitize_matcher(matcher) {
const originalMatcher =
typeof matcher._call === "function" ? matcher._call() : matcher._call;
const originalMatcher = typeof matcher._call === 'function' ? matcher._call() : matcher._call;
return originalMatcher.type ? originalMatcher.value : originalMatcher;
}
class DetoxMatcher {
Expand Down
24 changes: 10 additions & 14 deletions detox/src/ios/earlgreyapi/GREYActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,32 @@

function sanitize_greyDirection(action) {
switch (action) {
case "left":
case 'left':
return 1;
case "right":
case 'right':
return 2;
case "up":
case 'up':
return 3;
case "down":
case 'down':
return 4;

default:
throw new Error(
`GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}`
);
throw new Error(`GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}`);
}
}
function sanitize_greyContentEdge(action) {
switch (action) {
case "left":
case 'left':
return 0;
case "right":
case 'right':
return 1;
case "top":
case 'top':
return 2;
case "bottom":
case 'bottom':
return 3;

default:
throw new Error(
`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`
);
throw new Error(`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`);
}
}
class GREYActions {
Expand Down
2 changes: 1 addition & 1 deletion detox/src/ios/earlgreyapi/GREYConditionDetox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function sanitize_greyElementInteraction(value) {
return {
type: "Invocation",
type: 'Invocation',
value
};
}
Expand Down
48 changes: 22 additions & 26 deletions detox/src/ios/earlgreyapi/GREYMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,57 @@ function sanitize_uiAccessibilityTraits(value) {
let traits = 0;
for (let i = 0; i < value.length; i++) {
switch (value[i]) {
case "button":
case 'button':
traits |= 1;
break;
case "link":
case 'link':
traits |= 2;
break;
case "header":
case 'header':
traits |= 4;
break;
case "search":
case 'search':
traits |= 8;
break;
case "image":
case 'image':
traits |= 16;
break;
case "selected":
case 'selected':
traits |= 32;
break;
case "plays":
case 'plays':
traits |= 64;
break;
case "key":
case 'key':
traits |= 128;
break;
case "text":
case 'text':
traits |= 256;
break;
case "summary":
case 'summary':
traits |= 512;
break;
case "disabled":
case 'disabled':
traits |= 1024;
break;
case "frequentUpdates":
case 'frequentUpdates':
traits |= 2048;
break;
case "startsMedia":
case 'startsMedia':
traits |= 4096;
break;
case "adjustable":
case 'adjustable':
traits |= 8192;
break;
case "allowsDirectInteraction":
case 'allowsDirectInteraction':
traits |= 16384;
break;
case "pageTurn":
case 'pageTurn':
traits |= 32768;
break;
default:
throw new Error(
`Unknown trait '${
value[i]
}', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios`
`Unknown trait '${value[i]}', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios`
);
}
}
Expand All @@ -70,19 +68,17 @@ function sanitize_uiAccessibilityTraits(value) {
}
function sanitize_greyContentEdge(action) {
switch (action) {
case "left":
case 'left':
return 0;
case "right":
case 'right':
return 1;
case "top":
case 'top':
return 2;
case "bottom":
case 'bottom':
return 3;

default:
throw new Error(
`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`
);
throw new Error(`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`);
}
}
class GREYMatchers {
Expand Down
3 changes: 3 additions & 0 deletions generation/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package.json
package-lock.json

3 changes: 0 additions & 3 deletions generation/.prettierrc

This file was deleted.

61 changes: 29 additions & 32 deletions generation/__tests__/android.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,77 @@
const fs = require("fs");
const remove = require("remove");
const androidGenerator = require("../adapters/android");
const fs = require('fs');
const remove = require('remove');
const androidGenerator = require('../adapters/android');

describe("Android generation", () => {
describe('Android generation', () => {
let ExampleClass;
let exampleContent;
beforeAll(() => {
// Generate the code to test
fs.mkdirSync("./__tests__/generated-android");
fs.mkdirSync('./__tests__/generated-android');

const files = {
"./fixtures/example.java": "./__tests__/generated-android/example.js"
'./fixtures/example.java': './__tests__/generated-android/example.js'
};

console.log("==> generating android files");
console.log('==> generating android files');
androidGenerator(files);

console.log("==> loading android files");
console.log('==> loading android files');
// Load
ExampleClass = require("./generated-android/example.js");
exampleContent = fs.readFileSync(
"./__tests__/generated-android/example.js",
"utf8"
);
ExampleClass = require('./generated-android/example.js');
exampleContent = fs.readFileSync('./__tests__/generated-android/example.js', 'utf8');
});

afterAll(() => {
// Clean up
remove.removeSync("./__tests__/generated-android");
remove.removeSync('./__tests__/generated-android');
});

describe("methods", () => {
it("should expose the functions", () => {
describe('methods', () => {
it('should expose the functions', () => {
expect(ExampleClass.multiClick).toBeInstanceOf(Function);
});

it("should generate type checks", () => {
it('should generate type checks', () => {
expect(() => {
ExampleClass.multiClick("FOO");
ExampleClass.multiClick('FOO');
}).toThrowErrorMatchingSnapshot();
});

it("should return adapter calls", () => {
it('should return adapter calls', () => {
const result = ExampleClass.multiClick(3);
expect(result.method).toBe("multiClick");
expect(result.target.value).toBe("com.wix.detox.espresso.DetoxAction");
expect(result.args[0].type).toBe("Integer");
expect(result.method).toBe('multiClick');
expect(result.target.value).toBe('com.wix.detox.espresso.DetoxAction');
expect(result.args[0].type).toBe('Integer');
expect(result.args[0].value).toBe(3);

expect(result).toMatchSnapshot();
});

it("should add a sanitizer for the function with the correct name", () => {
it('should add a sanitizer for the function with the correct name', () => {
const fn = ExampleClass.scrollInDirection;

expect(() => {
fn(3, 42);
}).toThrowError();

expect(() => {
fn("down", 42);
fn('down', 42);
}).not.toThrowError();

expect(fn("down", 42)).toMatchSnapshot();
expect(fn('down', 42)).toMatchSnapshot();
});
});

describe("validation", () => {
describe("Matcher<View>", () => {
it("should fail getting no object", () => {
describe('validation', () => {
describe('Matcher<View>', () => {
it('should fail getting no object', () => {
expect(() => {
ExampleClass.matcherForAnd("I am a string", "I am one too");
ExampleClass.matcherForAnd('I am a string', 'I am one too');
}).toThrowErrorMatchingSnapshot();
});

it("should fail with a wrong class", () => {
it('should fail with a wrong class', () => {
class AnotherClass {}
const x = new AnotherClass();

Expand All @@ -88,8 +85,8 @@ describe("Android generation", () => {
class Matcher {
_call() {
return {
target: { type: "Class", value: "Detox.Matcher" },
method: "matchNicely"
target: { type: 'Class', value: 'Detox.Matcher' },
method: 'matchNicely'
};
}
}
Expand Down
Loading

0 comments on commit c6b1b67

Please sign in to comment.