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

Use config in test environment #35

Merged
merged 1 commit into from Apr 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions bin/near
Expand Up @@ -78,13 +78,7 @@ const newProject = {
handler: (argv) => exitOnError(main.newProject(argv))
};

const configPath = process.cwd() + '/src/config';
Copy link
Contributor

Choose a reason for hiding this comment

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

does this setup allow you to easily have different config for test and staging/prod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let config = {};
try {
config = require(configPath)(process.env.NODE_ENV || 'development');
} catch (e) {
console.log(`Didn't find config at ${configPath}\n`);
}
let config = require('../get-config')();
yargs // eslint-disable-line
.option('nodeUrl', {
desc: 'NEAR node URL',
Expand Down
3 changes: 1 addition & 2 deletions blank_project/package.json
Expand Up @@ -9,8 +9,7 @@
"deploy": "npm run build && npm run deploy:contract && npm run deploy:pages",
"prestart": "npm run build && npm run deploy:contract",
"start": "python3 -mhttp.server --directory src",
"test": "npm run build && jest test --env=near-shell/local_test_environment",
"test-on-devnet": "npm run build && jest test --env=near-shell/devnet_test_environment"
"test": "npm run build && jest test --env=near-shell/test_environment"
},
"devDependencies": {
"assemblyscript": "github:nearprotocol/assemblyscript.git",
Expand Down
67 changes: 0 additions & 67 deletions devnet_test_environment.js

This file was deleted.

10 changes: 10 additions & 0 deletions get-config.js
@@ -0,0 +1,10 @@

module.exports = function getConfig() {
const configPath = process.cwd() + '/src/config';
try {
return require(configPath)(process.env.NODE_ENV || 'development');
} catch (e) {
console.log(`Didn't find config at ${configPath}\n`);
return {};
}
}
3 changes: 1 addition & 2 deletions test/new_project.sh
Expand Up @@ -7,5 +7,4 @@ cd tmp-project
npm install
npm uninstall near-shell
npm install ../
npm run build
npm run test-on-devnet
NODE_ENV=development npm run test
26 changes: 13 additions & 13 deletions local_test_environment.js → test_environment.js
Expand Up @@ -13,26 +13,26 @@ class LocalTestEnvironment extends NodeEnvironment {
this.global.nearlib = require('nearlib');
this.global.nearlib.dev = require('nearlib/dev');
this.global.window = {};
this.global.testSettings = {
let config = require('./get-config')();
this.global.testSettings = config;
config = Object.assign(config, {
contractName: "test" + Date.now(),
accountId: "test" + Date.now(),
nodeUrl: "http://localhost:3030",
deps: {
storage: this.createFakeStorage(),
keyStore: new nearlib.InMemoryKeyStore(),
createAccount: dev.createAccountWithLocalNodeConnection
}
};
const near = await dev.connect(this.global.testSettings);
accountId: "test" + Date.now()
});
config.deps = Object.assign(config.deps || {}, {
storage: this.createFakeStorage(),
keyStore: new nearlib.InMemoryKeyStore(),
});
const near = await dev.connect(config);

const keyWithRandomSeed = await nearlib.KeyPair.fromRandomSeed();
await dev.createAccountWithLocalNodeConnection(this.global.testSettings.contractName, keyWithRandomSeed.getPublicKey());
this.global.testSettings.deps.keyStore.setKey(this.global.testSettings.contractName, keyWithRandomSeed);
await config.deps.createAccount(config.contractName, keyWithRandomSeed.getPublicKey());
config.deps.keyStore.setKey(config.contractName, keyWithRandomSeed);

// deploy contract
const data = [...fs.readFileSync('./out/main.wasm')];
await near.waitForTransactionResult(
await near.deployContract(this.global.testSettings.contractName, data));
await near.deployContract(config.contractName, data));

await super.setup();
}
Expand Down