I have to run the rails server and protractor using single command. So, I choose to used the gulp task and below is my gulp file:
'use strict';
var gulp = require('gulp');
var shell = require('gulp-shell');
var runSequence = require('run-sequence');
var protractor = require('gulp-protractor').protractor
var exec = require('child_process').exec;
gulp.task('start-server',function(cb){
exec('RAILS_ENV=test rails s -p 8000 -P 42324',function(err,stdout,stderr){
console.log(stdout);
console.log(stderr);
cb(err);
});
exec('start-protractor',function(err,stdout,stderr){
'protractor protractor.conf.js'
});
});
gulp.task('rails-kill',shell.task([
"kill 'cat ../tmp/pids/server.pid'"
]));
gulp.task('e2e-test', function(){
runSequence('start-server','rails-kill')
});
gulp.task('default',['e2e-test']);
When I run the gulp in the terminal rails server started but never run the protractor.Below is terminal output
Sab-MacBook-Pro:spec sab$ gulp
[14:12:41] Using gulpfile ~/RubymineProjects/myproject/spec/gulpfile.js
[14:12:41] Starting 'e2e-test'...
[14:12:41] Starting 'start-server'...
[14:12:41] Finished 'e2e-test' after 7.15 ms
[14:12:41] Starting 'default'...
[14:12:41] Finished 'default' after 9.69 μs
Any help will be really appreciated.
Thanks
Sabbu
I solve my problem using the gems instead of using gulp task.I am posting the answer here so that it may help others if they are looking the thing that I achieved using the rails gem.Here is the link of the gems:
https://github.com/tyronewilson/protractor-rails
Thanks
Sabbu
Related
I would put this on stack overflow but it's specific to the hackathon. This is for the HardHat tutorial. I am trying to execute my get-number function on my smart contract. My contract is deployed. This is my command: npx hardhat get-number --contract 0x5FbDB2315678afecb367f032d93F642f64180aa3. This is the error I get: Error: call revert exception (method="getNumber()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0). Any thoughts would help...Thanks.
Here is the Task
task("get-number", "Reads the number")
.addParam("contract", "The contract's address")
.setAction(async (taskArgs) => {
const contractAddr = taskArgs.contract;
const MyFirstContract = await ethers.getContractFactory('MyFirstContract');
const accounts = await ethers.getSigners();
const signer = accounts[0];
const myFirstContract = await new ethers.Contract(contractAddr, MyFirstContract.interface, signer);
let result = BigInt(await myFirstContract.getNumber()).toString();
console.log('Stored number is: ' + result);
});
module.exports = {};
I had similar error when following along with this hackathon tutorial.
My fix was to specify the --network when executing my task, get-number. So, in your example:
npx hardhat get-number --network localhost --contract 0x5FbDB2315678afecb367f032d93F642f64180aa3
This will execute the task using the Hardhat network the demo instructed you to start when you ran npx hardhat node
Hardhat Network doc
See Running Stand-Alone doc
I asked on the hackathon Discord why the demo didn't pass this, yet still worked, but haven't yet received an answer.
I have the same problem, and the way I fixed it is to start hardhat with npx hardhat node --hostname 0.0.0.0 instead of npx hardhat node
You'll need to deploy the contract to localhost as well: npx hardhat run scripts/deploy.js --network localhost
Then using npx hardhat --network localhost to call the 2 functions.
Using OS X Sierra
I have a rails app with two parts: front-end and back-end.
On back-end I am using rails 4.
On the front-end I am using Angular.
Whenever I have to start the server locally (for development or test) I use 3 distinct console windows.
one to run grunt watch"
another to run http-server ./build/ -p 8000 -c-1
and the last to run rails server
My local backend repository is just a clone of what is running on production.(minus server configuration)
When I use the fronted connected to my remote server it works without problems. However, when I run the backend locally and try to log in, all I get is the following log, and no responses:
=> Booting WEBrick
=> Rails 4.2.7 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2017-01-02 16:19:21] INFO WEBrick 1.3.1
[2017-01-02 16:19:21] INFO ruby 2.3.3 (2016-11-21) [x86_64-darwin15]
[2017-01-02 16:19:21] INFO WEBrick::HTTPServer#start: pid=10496 port=3000
The front end throws the following error:
XMLHttpRequest cannot load localhost:3000/auth_user?
email=admin#railsapp.com&password=VVVVVVVV. Cross origin requests are
only supported for HTTP.
My Angular endpoint file
angular.module( 'common.config', [] )
.factory('endpoints', function() {
var host = 'development';
if (['live.companysite.com'].indexOf(window.location.host) > -1) {
host = 'production';
} else if (['companysite.com'].indexOf(window.location.host) > -1) {
host = 'development';
} else {
host = 'local';
}
var endpoints = {
'production': {
root: 'http://live.companysite.com/'
},
'development': {
root: 'http://companysite.com/'
},
'local': {
root: 'localhost:3000/'
}
};
return endpoints[host];
});
I know that it should be a CORS problem, but as it works perfectly with two remote servers (production and test) I believe that my local configuration might be the problem.
'localhost:3000auth_user?emai' I think you are missing an '/' before auth_user and after :3000, check the line where you define the api in your angular project, probably you need to add a slash .
Check changing this in your config:
'local': { root: "http:// localhost:3000/" }
In the past I always bundled my Angular 1 and Rails apps together and typically used heroku, which has worked great for me. Now that I'm over to Angular 2 I want to separate out my Angular and Rails code. I've created a very basic Angular 2 app via the Angular-Cli, but I haven't been able to figure out how to deploy it to Heroku. I'm not using expressjs or anything like that. Anyone figure it out yet?
Ok I came up with a solution. I had to add a very basic PHP backend, but it's pretty harmless. Below is my process.
First setup a heroku app and Angular 2 app.
Create your heroku app
Set the heroku buildpack to heroku/php
heroku buildpacks:set heroku/php --app heroku-app-name
Create a project via Angular-Cli
Add a index.php file to /scr with the below snippet
<?php include_once("index.html"); ?>
Add a Procfile to /scr with the below snippet
web: vendor/bin/heroku-php-apache2
Added /deploy to the .gitignore
Now I used a npm package to push a tarballs to heroku
Here's a simple package to upload the tarball, https://www.npmjs.com/package/heroku-deploy-tarball
npm i heroku-deploy-tarball --save
I'm also using tar.gz to create the tarball
npm i tar.gz --save
Then I created the deploy.js file at the root of my projecdt with the following code. I first run the buildCommand specified and then move the index.php and Profile to the dist folder. I then tarball the entire dist folder and it gets uploaded to heroku.
var deploy = require('heroku-deploy-tarball');
var targz = require('tar.gz');
var exec = require('child_process').exec;
var requestedTarget = process.argv[2];
if (!requestedTarget) {
console.log('You must specify a deploy target');
return;
}
var targets = {
production: {
app: 'heroku-app-name',
tarball: 'deploy/build.tar.gz',
buildCommand: 'ng build --prod'
}
}
var moveCompressFiles = function (callback) {
exec('cp ./src/index.php ./dist/index.php',
function(err) {
if(err)
console.log(err);
console.log('index.php was copied.');
});
exec('cp ./src/Procfile ./dist/Procfile',
function(err) {
if(err)
console.log(err);
console.log('Procfile was copied.');
});
new targz().compress('./dist', './deploy/build.tar.gz',
function(err){
if(err)
console.log(err);
else
callback();
console.log('The compression has ended!');
});
};
console.log('Starting ' + targets[requestedTarget].buildCommand);
exec(targets[requestedTarget].buildCommand, {maxBuffer: 1024 * 500}, function(error) {
if (!error) {
console.log(targets[requestedTarget].buildCommand + ' successful!');
moveCompressFiles(function () {
deploy(targets[requestedTarget]);
});
} else {
console.log(targets[requestedTarget].buildCommand + ' failed.', error);
}
});
Now just run node deploy production and it should deploy to heroku.
Edit
Just got word from heroku that they are working on an experimental buildpack that would allow for static sites like this. Here is the link to the build pack.
I'm trying to create an easy workflow for package development and was hoping someone could pint me in the right direction. In short, once a css file has been updated I want to be able to run a command (php artisan vendor:publish --force) to automatically publish the files.
Can this be done with Elixir and if so could anyone point me in the right direction?
regards
This was incredibly useful to get me on the right track, but I found a slightly simpler solution that I thought I would share:
var elixir = require('laravel-elixir');
var gulp = require("gulp");
var shell = require("gulp-shell");
elixir(function(mix) {
mix.task('publish_assets', ['resources/assets/**/*.scss', 'resources/assets/**/*.js']);
});
gulp.task('publish_assets', shell.task([
"php ../../../../artisan vendor:publish --tag=public --force"
]));
It watches all of the js and sass files for changes and runs the publish assets task. Mine is set to only publish the "public" tagged files, and a quick note as well, you will need to install the gulp-shell utility (https://www.npmjs.com/package/gulp-shell) for either of these.
if anyone is looking, this works nicely:
var gulp = require("gulp");
var shell = require("gulp-shell");
var elixir = require("laravel-elixir");
elixir.extend("publish", function() {
var baseDir = this.assetsDir;
gulp.task("publish_assets", function() {
gulp.src("").pipe( shell( [
"php ../../../artisan vendor:publish --force",
"cd ../../../ ; gulp"
]));
});
this.registerWatcher("publish_assets", [
baseDir + '**/*.scss',
baseDir + '**/*.js'
]);
return this.queueTask("publish_assets");
});
Is there a way to use node-inspector to debug unit tests with Jest? It would be nice to step through sometimes to see why tests are failing
I have tried a few ways
node-debug jest --runInBand
from the as well as starting up the inspector first eg
$ node-inspector
$ node --debug-brk .\node_modules\jest-cli --runInBand
and then navigate to http://127.0.0.1:8080/debug?port=5858
I have found that occasionally (1 in 10 or so times), the debugger opens the jest src files and its possible to debug them. Generally though, the scripts in the debugger only contain a 'no domain' folder and another irrelevant folder.
Also the test scripts themselves are never loaded in the debugger.
Has anyone tried this before?
Looks like the issue is that jest is using harmonize, which spawns a child process to ensure that the --harmony option is used.
harmonize/harmonize.js, lines 30-35
var node = child_process.spawn(process.argv[0], ['--harmony'].concat(process.argv.slice(1)), {});
node.stdout.pipe(process.stdout);
node.stderr.pipe(process.stderr);
node.on("close", function(code) {
process.exit(code);
});
I was able to successfully debug jest tests (although tests that use JSX transforms are incredibly slow) by commenting out the code that jest is using to spawn the harmonized process.
node_modules/jest-cli/bin/jest.js, last lines of the file:
if (require.main === module) {
//harmonize(); <--- comment out
_main(function (success) {
process.exit(success ? 0 : 1);
});
}
Then you can run:
$ node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand
Jest relies on the --harmony flag being there, so that's why we need to add it back with --nodejs --harmony. We also add --runInBand so that the tests run in sequence, not in parallel.
This opens up the web debugger, and you can debug the tests, although it can be pretty slow to get to the test you want. Please comment if anyone knows a way to make this faster, and I'll update my answer.
You can add this to your package.json to make it easier to kick off:
...
scripts: {
"test": "jest",
"test-debug": "node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand"
}
...
Of course, main concern with this solution is the editing of the jest source code. Will think about how to make a pull request to make this stick.
Created Github Issue Here: https://github.com/facebook/jest/issues/152
This is now officially supported with Node >= 6.3.
Quoting Jest documentation:
Place a debugger; statement in any of your tests, and then, in your project's directory, run:
node --debug-brk --inspect ./node_modules/.bin/jest -i [any other arguments here]
This will output a link that you can open in Chrome. After opening that link, the Chrome Developer Tools will be displayed, and a breakpoint will be set at the first line of the Jest CLI script (this is done simply to give you time to open the developer tools and to prevent Jest from executing before you have time to do so). Click the button that looks like a "play" button in the upper right hand side of the screen to continue execution. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack.
Note: the -i cli option makes sure Jest runs test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.
More information on the V8 inspector can be found here: https://nodejs.org/api/debugger.html#debugger_v8_inspector_integration_for_node_js
Using Node 7.4.0, Jest 18.x, and the jest-environment-node-debug package (from this comment), it's now possible to use the chrome devtools to debug Jest tests:
$ npm install -D jest-environment-node-debug
$ node --inspect-brk ./node_modules/.bin/jest -i --env jest-environment-node-debug
Here's a Gruntfile.js config to automate #Sean's answer with Grunt.
grunt testd
OR
grunt testd --tests=MyTestName
OR
grunt testd --tests=MyTestName,AnotherTestName
Requires "node-inspector" (must be installed globally to get the node-debug bin in your path), "lodash", "jest-cli" and "grunt-shell" node modules.
var _ = require('lodash');
var commaSplitToRegex = function(input) {
return _.map(input.split(','), function(part) {
return '(' + part + ')';
}).join('|');
};
var getTestRegex = function(tests) {
if (tests) {
return '.*' + commaSplitToRegex(tests) + '.*';
}
return '.*';
}
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.initConfig({
shell: {
jestd: {
command: function() {
var testsRegex = getTestRegex(grunt.option('tests'));
var cmd = 'node-debug --nodejs --harmony ./node_modules/jest-cli/bin/jest.js --runInBand --config="test_utils/jest.json"';
if (testsRegex) {
cmd += ' "' + testsRegex + '"';
}
return cmd;
}
},
monkeypatchjest: {
command: 'sed -i.bak s\\/harmonize\\(\\)\\;\\/\\\\/\\\\/wtf\\/g ./node_modules/jest-cli/bin/jest.js'
},
unmonkeypatchjest: {
command: 'sed -i.bak s\\/\\\\/\\\\/wtf\\/harmonize\\(\\)\\;\\/g ./node_modules/jest-cli/bin/jest.js'
}
}
});
grunt.registerTask('testd', 'Run tests with debugger.', ['shell:monkeypatchjest', 'shell:jestd']);
};