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

Detox #26

Merged
merged 60 commits into from
Oct 26, 2018
Merged

Detox #26

merged 60 commits into from
Oct 26, 2018

Conversation

hadasz
Copy link
Contributor

@hadasz hadasz commented Oct 20, 2018

Related Issue
Supports Issue #7
Related PRs
This PR is not dependent on any other PR
What does this PR do?
Sets up detox for end to end testing and unit testing modules with substantial native components
Description of Changes
added an e2e folder where e2e test specs can be written.
What gif most accurately describes how I feel towards this PR?
(https://media.giphy.com/media/5Yl08OSg4AckeNHpDc/giphy.gif)

@barlock
Copy link
Contributor

barlock commented Oct 22, 2018

The linter is complaining.

e2e/init.js Show resolved Hide resolved
README.md Outdated

### End to End Tests

Run `detox build` followed by `detox test` for end to end tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write an npm script to automate this? just stick detox build && detox test in there.

Also, did travis not work? What broke?

it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
});
/* it('should show hello screen after tap', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for commented code? Looks like boiler plate you didn't delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder -- will be deleted in next pull request

e2e/config.json Show resolved Hide resolved
package.json Outdated
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/sojourn.app",
"build": "cp index.test.js index.js && xcodebuild -project ios/sojourn.xcodeproj -configuration Debug -scheme sojourn -destination id=AC488766-22CC-4F2F-AEE5-F699F8D3BE7A -derivedDataPath ios/build",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always used the react-native cli to do builds instead of relying on xcode. What's the difference?

Is the id one specifically on your machine? I'm worried that it isn't portable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took out the ID. react-native run-ios starts it's own simulator, so not worth it to use

//arguments: file - plaintext file
//return value:encrypted file
export async function encryptWithAes(privateKey, plainTextFile) {
const iv = 'sixteen bytes iv'; //To DO: randomly generate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you plan on using an IV? Per file/user? I think they're optional, though definitely good practice, yeah?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IV will be used per file, so nobody can do cryptanalysis on it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any thoughts on how we're going to store the IV? I'm guessing it will need to go in the azure "how to decrypt" file? (Obviously not necessary for this pr, just curious)

e2e/init.js Outdated
afterAll(async () => {
await adapter.afterAll();
console.log('cleaning up');
exec('cp index.debug.js index.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love the idea of having a completely separate app to do e2e testing. For the short term it's a lovely PoC. What did you have in mind for how this would look in the long run?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, the build copies the .test.js and this one copies .debug back over top? Is that a bug?

Is it possible to get the copying of files in the same file? The code distance seems great to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing this with environment variables, but alas, it is not trivial to pass environment variables into a react-native app. One potential work around is dotenv (https://github.com/zetachang/react-native-dotenv) , but you can only have a different .env file for release and debug, so it boils down to the same problem.
Different files is the best thing I can think of right now. Will keep an open mind for possible changes, however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the setup cp into the beforeAll to keep the code distance small

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line now just be rm index.js?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe your not seeing errors b/c exec is a callback? using fs-extra will fix that.

});

it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fail if the encryption fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a placeholder test

testPrivateKey,
'ffffffffffffffffffffffffffffffffffffffffffffffffffff'
);
if (!aesOutput) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this ever be falsy? If it fails it looks like it will throw instead of returning an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been taken out in newest commit

.eslintrc.js Outdated
settings: {
react: {
pragma: 'React',
version: '16.5.0'
}
},
rules: {
'react/display-name': 'off'
'react/display-name': 'off',
'no-console': 'off'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like this rule. It usually catches a bunch of debug logic that doesn't need to be there.

Rather than do this, would it make more sense to use inline-ignores where it makes sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package.json Outdated
@@ -9,24 +9,30 @@
"build:truffle": "truffle compile",
"ios": "react-native run-ios",
"lint": "eslint .",
"jest": "yarn build:truffle && jest",
"jest": "yarn build:truffle && jest src/_tests_",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just learned that truffle requires you to use the top level test dir for truffle tests and it isn't changeable.

I'd like to keep the tests alongside the file CA: 7

My reasoning:

  • When reviewing code it means your test suite and file your testing are next to each other and there's less context switching during a review
  • git diff shows you the files next to each other and it's a quick personal test to make sure you wrote a test for every file you touched.

I just wanted to be able to specify one file for jest, because it's easier than using transformIgnore options.

I think you're looking for testPathIgnorePatterns

{
  testPathIgnorePatterns: [
    '/node_modules/', 
    '/e2e/', // this is what you want
    '/test/', // this will be coming in a pr soon b/c truffle
  ]
}

package.json Outdated
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@trackforce/react-native-aes-crypto": "^1.2.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "normal" one looks more popular. I think trackforce is doing the thing were they protect themselves from leftpad/eslint situations

package.json Outdated
@@ -35,9 +41,13 @@
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"browserify": "^12.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's new in this commit, remove it?

package.json Outdated
"drizzle": "git+https://github.com/trufflesuite/drizzle.git#1.2.3",
"drizzle-react": "^1.2.0",
"eth-block-tracker": "^4.0.3",
"get-random-values": "^1.1.1",
"global": "^4.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit easier for me to review dependencies when they're included with the code that's using it. It's also gives better history/thinking. For example, it was pretty easy for me to kill Drizzle sense I could just look at that PR and basically revert it.

Could you remove those that your not using?

.travis.yml Outdated
branches:
only:
- master
- master
os: osx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed detox, don't need this anymore

README.md Outdated

### End to End Tests

Run yarn e2e to run end to end tests. Because schemes other than debug and release are not trivial in react-native,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run `yarn e2e...`

const testPrivateKey =
'8238BAE35C77FE4AEBB2DEB1B83A6F0027A01D0E4D93BF5B81F7117796955A17';
export default class E2ETests extends Component {
constructor(props) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructors can't be async so doing async here means you have uncaught exceptions.

The right place is compomnentDidMount

class SomeClass extends Component {
  state = { input16: 0, input20: 0, input48: 0 };
}

☝️ Class properties mean less typing!

super(props);
this.state = { input16: 0, input20: 0, input48: 0 };
inputSizes.map(inputSize => {
this.encryptForSize(inputSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to do this on componentDidMount() for initialization

https://reactjs.org/docs/react-component.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next PR

}
this.setState({ ['input'.concat(sizeInBytes)]: aesOutput.ciphertext });
console.warn(this.state);
return 'success';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return seems unnecessary ?

e2e/init.js Outdated
afterAll(async () => {
await adapter.afterAll();
console.log('cleaning up');
exec('cp index.debug.js index.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the setup cp into the beforeAll to keep the code distance small

index.ios.js Outdated
@@ -0,0 +1,6 @@
/** @format */
import './polyfill';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polyfill was removed in #30

index.e2e.js Outdated
@@ -0,0 +1,5 @@
import './polyfill';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polyfill was removed in #30

@@ -1,5 +1,15 @@
{
"images": [
{
"idiom": "iphone",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using these images?

package.json Outdated
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad merge, this was moved to dev

e2e/init.js Outdated
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
exec('cp index.test.js index.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean index.e2e.js?

e2e/init.js Outdated
afterAll(async () => {
await adapter.afterAll();
console.log('cleaning up');
exec('cp index.debug.js index.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this line now just be rm index.js?

e2e/init.js Outdated
afterAll(async () => {
await adapter.afterAll();
console.log('cleaning up');
exec('cp index.debug.js index.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe your not seeing errors b/c exec is a callback? using fs-extra will fix that.

@barlock barlock merged commit 1f8fb50 into master Oct 26, 2018
@barlock barlock deleted the detox branch October 31, 2018 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants