Waiting on 1 test - jestjs

I have the following test
// tests/CheckboxWithLabel-test.js
jest.dontMock('../test.js');
describe('CheckboxWithLabel', function() {
it('changes the text after click', function() {
var React = require('react/addons');
var CheckboxWithLabel = require('../test.js');
var TestUtils = React.addons.TestUtils;
// Render a checkbox with label in the document
var checkbox = TestUtils.renderIntoDocument(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
// Verify that it's Off by default
var label = TestUtils.findRenderedDOMComponentWithTag(
checkbox, 'label');
expect(label.getDOMNode().textContent).toEqual('Off');
// Simulate a click and verify that it is now On
var input = TestUtils.findRenderedDOMComponentWithTag(
checkbox, 'input');
TestUtils.Simulate.change(input);
expect(label.getDOMNode().textContent).toEqual('On');
});
});
when I try to run it though using jest, I get the following error: Waiting on 1 test
I run npm test
What should I do?

You did not specify the version of Node you were using. Your problem could be because you are using a newer version of Node and Jest works with version 0.10.0. This is an open issue on Github (https://github.com/facebook/jest/issues/243)
To downgrade your version of node, use the n package as follows:
npm install -g n # Install n globally
n 0.10 # Installing the correct version of node
This can result in some weird problems with your current packages, so delete your node_modules folder and perform a clean install.

Related

Can't use crypto in NPM dependency in Electron app

I'm building an Electron app (with Ionic) to digitally sign PDFs with p12 certificates using node-signpdf (https://www.npmjs.com/package/node-signpdf). I've had problems which I solved by using require ('electron').remote for example for fs.
I've also installed the same node version in my OS (MacOS Catalina) as the same one that electron is using (Node v12.4.0).
The problem is that one of the NPM dependencies uses crypto and it shows as undefined with the next error:
HomePage.html:39 ERROR TypeError: _crypto.randomBytes is not a function
at Object.ctx.seedFileSync (prng.js:340)
at _reseedSync (prng.js:210)
at Object.ctx.generateSync (prng.js:163)
at Object.ctx.generate (prng.js:80)
at Object.ctx.getBytes (random.js:92)
at _modPow (rsa.js:431)
at Object.push../node_modules/node-forge/lib/rsa.js.pki.rsa.encrypt (rsa.js:501)
at Object.key.sign (rsa.js:1245)
at addSignerInfos (pkcs7.js:534)
at Object.sign (pkcs7.js:377)
What I can see is that node-signpdf uses node-forge as a dependency, and node-forge loads crypto inside prng.js this way:
var _crypto = null;
if(forge.util.isNodejs && !forge.options.usePureJavaScript &&
!process.versions['node-webkit']) {
_crypto = require('crypto');
}
I've tried changing that part of the code to use crypto-js or browserfy-crypto (this last one doesn't even build and hasn't been updated in years), but I keep getting the error shown above.
EDIT 1:
This is how I'm implementing the signature in my service:
public signFile(pathToFile: string, pathToCert: string): void {
const fs = (<any>window).require('fs');
let certBuffer = fs.readFileSync(pathToCert);
let fileBuffer = fs.readFileSync(pathToFile);
fileBuffer = plainAddPlaceholder({
pdfBuffer: fileBuffer,
reason: 'I have reviewed it.',
signatureLength: 1612,
});
const signedPdf = signer.sign(fileBuffer, certBuffer, {passphrase: 'qwertyui'});
}
The code adds the placeholder to add the signature, the problem comes in signer.sign
EDIT 2:
When I run the app if I type in console: require ('crypto') I see the methods, so it looks like it's loaded in the global scope, the problem seems to be in the NPM dependency of node-forge.
EDIT 3:
I've changed require('crypto') to window.require('crypto') and started working. But I think I'll have to make postinstall script to modify it.
Is there a better way?
-
How can I make this crypto thing work? I ran out of ideas. Maybe you can spare some?
Thanks for your time!

Cannot run Angular-cli at node 10.16.0

Here is my computer information:
node version 10.16.0
npm version 6.9.0
Environment Variables C:\Users\tran.sonhoang\AppData\Roaming\npm\node_modules\#angular\cli\bin
My problem is when I run ng new app-name I will get the file with this info
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch(_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// Some older versions of Node do not support let or const.
var version = process.version.substr(1).split('.');
if (Number(version[0]) < 10 || (Number(version[0]) === 10 && Number(version[1]) < 9)) {
process.stderr.write(
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI 8.0+.\n' +
'The official Node.js version that is supported is 10.9 or greater.\n\n' +
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
);
process.exit(3);
}
require('../lib/init');
This issue is so strange to me since this is the first time I see this issue with angular-cli.
What I have tried:
Removed node and install again the same version.
Remove npm cache + update npm
Remove Angular-cli and re-install
But It still not fix this issue. Any help will be appreciated.Thanks!

ng v is working in cmd but not working in vs code

SO i wanted to create an web application so i downloaded VS code and node.js the current version and i installed everything successfully.
When i type ng v in cmd i am able to view the version of angular but when i open a folder and run the same command in vs code i get an error code like this
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch(_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// Some older versions of Node do not support let or const.
var version = process.version.substr(1).split('.');
if (Number(version[0]) < 8 || (Number(version[0]) === 8 &&
Number(version[1]) < 9)) {
process.stderr.write(
'You are running version ' + process.version + ' of Node.js, which is not supported by Angular CLI v6.\n' +
'The official Node.js version that is supported is 8.9 and greater.\n\n' +
'Please visit https://nodejs.org/en/ to find instructions on how to update Node.js.\n'
);
process.exit(3);
}
require('../lib/init');
i know this says node version is < 8 but my node version is 12.1.0 which is clearly greater than version 8. I even tried to uninstall it and reinstall it but still i am getting this error. PLEASE HELP MEE

Error: Cannot find module 'togeojson'

I am attempting to use this module in node.js and am running into an "Error: Cannot find module 'togeojson'" error when I attempt to use the documented example code:
// using togeojson in nodejs
var tj = require('togeojson'),
fs = require('fs'),
// node doesn't have xml parsing or a dom. use xmldom
DOMParser = require('xmldom').DOMParser;
var kml = new DOMParser().parseFromString(fs.readFileSync('foo.kml', 'utf8'));
var converted = tj.kml(kml);
var convertedWithStyles = tj.kml(kml, { styles: true });
I ran npm init in the same directory that my app.js file (where the above code resides) is stored and I used the --save flag when installing the #mapbox/togeojson package to my application.
I am running node version 8.11.2 and npm v 6.1.0.
How do I go about debugging an issue like this in node/npm?
It is #mapbox/togeojson package, not togeojson, so it should be required like:
var tj = require('#mapbox/togeojson');

Installing bower packages after running yeoman generator

I'm having trouble getting this to work and even finding solutions through google on how to make it work.
Going to Bowers site shows they have a programatic API that looks like I should be able to run it in node, of course I can however it's not obeying my .bowerrc file and installing them into my dev folder created by yeoman.
Does this have something to do with the way yeoman works? Are the files and directories not quite available yet until after it's logged done()?
Here is my index.js
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var bower = require('bower');
var FoprojectGenerator = yeoman.generators.Base.extend({
sayHello: function(){
console.log(this.yeoman);
},
scaffoldFolders: function(){
this.mkdir("working");
this.mkdir("working/assets");
this.mkdir("working/assets/sass");
this.mkdir("working/assets/coffee");
this.mkdir('dev');
},
copyMainFiles: function(){
this.copy("_index.html", "working/index.html");
this.copy("_gruntfile.js", "Gruntfile.js");
this.copy("_package.json", "package.json");
this.copy("_bower.json", "bower.json");
this.copy("_.bowerrc", ".bowerrc");
this.copy("assets/sass/_site.sass", "working/assets/sass/site.sass");
this.copy("assets/sass/_mixins.sass", "working/assets/sass/_mixins.sass");
this.copy("assets/sass/_normalize.sass", "working/assets/sass/_normalize.sass");
this.copy("assets/coffee/_scripts.coffee", "working/assets/coffee/scripts.coffee");
},
installDependencies: function(){
var done = this.async();
console.log("\nInstalling Node Dependencies\n");
this.npmInstall("", function(){
console.log("\nInstalling Bower Packages\n");
bower.commands
.install()
.on('end', function(){
done();
});
});
}
});
module.exports = FoprojectGenerator;
Like I said it runs great, but it installs it next to the bower.json as apposed to in the dev folder like I've defined in the .bowerrc file like so
{
"directory": "dev/bower_components"
}
When I run bower install after yeoman is done it installs the bower_components folder in the dev folder like it should.
Any guidance would be greatly appreciated!
Maybe the Yeoman generator you use could force you to install deps on a certian specific path.
Open Terminal and go to the root directory of your app.
type ls -la.
if you see .yo-rc.json, type cat .yo-rc.json.
Does it show any particular config for the path like below?
{
"generator-backbone-laser": {
"appPath": "app"
}
}
if so, delete .yo-rc.json.
a creator of Yoeman's generator sometimes set app path on that file.

Resources