I have my folder structure like this within integration folder, I have Page Object folder, where I have two js files i.e. LoginPage.js and SignUpPage.js
and outside of that PageObject folder, I have spec files i.e. LoginTestCases.spec.js and SignUpTestCases.spec.js
While running :
npx cypress open
It ran all js files present within Integration folder, but I want to run spec files only and i want to see only those files on my TestRunner as well.
I know that we do some little change in cypress.json file, but Don't remember at all.
Can anyone help me out, here?
In your cypress.json file, add the list of spec files you want to run under testFiles array, something like this. And this will only execute the spec files that you have mentioned and also in the order you have mentioned.
If your spec files are inside integration folder
"testFiles": [
"LoginTestCases.spec.js",
"SignUpTestCases.spec.js"
]
If the spec files are somewhere else, then you have to give the absolute path.
"testFiles": [
"path to TC/LoginTestCases.spec.js",
"path to TC/SignUpTestCases.spec.js"
]
In case you want to just get only the .spec.js files and you have a lot of files, you can use the wild card using:
"testFiles": ["*.spec.js"]
Related
Maybe I'm trying to do something silly, but I've got a web application (Angular2+), and I'm trying to build it in an extensible/modular way. In particular, I've got various, well, modules for lack of a better term, that I'd like to be able to include or not, depending on what kind of deployment is desired. These modules include various functionality that is implemented via extending base classes.
To simplify things, imagine there is a GenericModuleDefinition class, and there are two modules - ModuleOne.js and ModuleTwo.js. The first defines a ModuleOneDefinitionClass and instantiate an exported instance ModuleOneDefinition, and then registers it with the ModuleRegistry. The second module does an analogous thing.
(To be clear - it registers the ModuleXXXDefinition object with the ModuleRegistry when the ModuleXXX.js file is run (e.g. because of some other .js file imports one of its exports). If it is not run, then clearly nothing gets registered - and this is the problem I'm having, as I describe below.)
The ModuleRegistry has some methods that will iterate over all the Modules and call their individual methods. In this example, there might be a method called ModuleRegistry.initAllModules(), which then calls the initModule() method on each of the registered Modules.
At startup, my application (say, in index.js) calls ModuleRegistry.initAllModules(). Obviously, because index.js imports the exported ModuleRegistry symbol, this will cause the ModuleRegistry.js code to get pulled in, but since none of the exports from either of the two Module .js files is explicitly referenced, these files will not have been pulled in, and so the ModuleOneDefinition and ModuleTwoDefinition objects will not have been instantiated and registered with the ModuleRegistry - so the call to initAllModules() will be for naught.
Obviously, I could just put meaningless references to each of these ModuleDefinition objects in my index.js, which would force them to be pulled in, so that they were registered by the time I call initAllModules(). But this requires changes to the index.js file depending on whether I want to deploy it with ModuleTwo or without. I was hoping to have the mere existence of the ModuleTwo.js be enough to cause the file to get pulled in and the resulting ModuleTwoDefinition to get registered with the ModuleRegistry.
Is there a standard way to handle this kind of situation? Am I stuck having to edit some global file (either index.js or some other file it references) so that it has information about all the included Modules so that it can then go and load them? Or is there a clever way to cause JavaScript to execute all the .js files in a directory so that merely copying the files it would be enough to get them to load at startup?
a clever way to cause xxJavaScriptxx Node.js to execute all the .js files in a directory:
var fs = require('fs') // node filesystem
var path = require('path') // node path
function hasJsExtension(item) {
return item != 'index.js' && path.extname(item) === '.js'
}
function pathHere(item) {
return path.join('.', item)
}
fs.readdir('./', function(err, list) {
if (err) return err
list.filter(hasJsExtension).map(pathHere).forEach(require) // require them all
})
Angular is pretty different, all the more if it is ng serve who checks if your app needs a module, and if so serves the corresponding js file, at any time needed, not at first load time.
In fact your situation reminds me of C++ with header files Declaration and cpp files with implementation, maybe you just need a defineAllModules function before initAllModules.
Another way could be considering finding out how to exclude those modules from ng-serve, and include them as scripts in your HTML before the others, they would so be defined (if present and so, served), and called by angular if necesary, the only cavehat is the error in the console if one script tag is not fetched, but your app will work anyway, if it supposed to do so.
But anyway, it would be declaring/defining those modules somewhere in ng-serve and also in the HTML.
In your own special case, and not willing to under-evalute ng-serve, but is the total js for your app too heavy to be served at once? (minified and all the ...), since the good-to-go solution may be one of the many tools to build and rebuild your production all.js from your dev js folder at will, or like you said, with a drag&drop in your folder.
Such tool is, again, server-side, but even if you only can push/FTP your javascript, you could use it in your prefered dev environment and just push your new version. To see a list of such tools google 'YourDevEnvironment bundle javascript'.
To do more with angular serve and append static js files under specific conditions, you should use webpack so the first option i see here is eject your webpack configuration and after that you can specify what angular should load or not.
With that said, i will give an example:
With angular cli and ng serve any external javascript files you wanna include, you have to put them inside the scripts array in the angular-cli.json file.However you can not control which file should be included and which one not.
By using webpack configuration you can specify all these thing by passing a flag from your terminal to the webpack config file and do all the process right there.
Example:
var env.commandLineParamater, plugins;
if(env.commandLineParamater == 'production'){
plugins = [
new ScriptsWebpackPlugin({
"name": "scripts",
"sourceMap": true,
"filename": "scripts.bundle.js",
"scripts": [
"D:\\Tutorial\\Angular\\demo-project\\node_moduels\\bootstrap\\dist\\bootstrap.min.js",
"D:\\Tutorial\\Angular\\demo-project\\node_moduels\\jquery\\dist\\jquery.min.js"
],
"basePath": "D:\\Tutorial\\Angular\\demo-project"
}),
]}else{
plugins = [
new ScriptsWebpackPlugin({
"name": "scripts",
"sourceMap": true,
"filename": "scripts.bundle.js",
"scripts": [
"D:\\Tutorial\\Angular\\demo-project\\node_moduels\\bootstrap\\dist\\bootstrap.min.js"
],
"basePath": "D:\\Tutorial\\Angular\\demo-project"
}),
]
}
then:
module.exports = (env) => {
"plugins": plugins,
// other webpack configuration
}
The script.js bundle will be loaded before your main app bundle and so you can control what you load when you run npm run start instead of ng-serve.
To Eject your webpack configuration, use ng eject.
Generally speaking, when you need to control some of angular ng-serve working, you should extract your own webpack config and customize it as you want.
I configured my IntelliJ IDEA to compile all .ts file to specific folder. Here's the configuration:
It works just fine. Here's my folder structure:
js/
| - typescript/
| - __test.ts
| - __test.js
| - __test.js.map
| - otherfile.js
The problem is that it outputs the .map files to the same folder as .js files. Since I'll be having a lot of .js files, the folder will look cluttered.
Is there a possibility to make IntelliJ IDEA to output .map files to a specific folder? I couldn't find any info about that...
Thank you!
tsc compiler doesn't have options for this - .map files, when generated, are always placed to the same folder as .js files.
See https://www.typescriptlang.org/docs/handbook/compiler-options.html for the list of available options.
if you like to move generated files to a different location, you can use build tools like Gulp, Grunt or Webpack. But, if you go this way, make sure that sourcemaps URL is properly generated (you need using --mapRoot cli option that controls the reference to the map file in the .js file to let the debugger know where to look for sourcemaps).
see TypeScript tsconfig Output files in certain folders, for example
in the Typescript Compiler options... I added --outDir ./.map. This affects both .js and .js.map files.
I created the files following the tutorial (http://dataops.co/android-login-registration-system-with-node-js-and-mongodb/), but unfortunately the error is shown like in the image.
I'm new to node.js and to this kind of programming.
PS.: All of the other files that are referred in the tutorial are right, and the chgpass.js is in the target folder.
Code from the file that requests the chgpass.js file AND the tree from the folder (open with Word and select MS-DOS):
http://www.mediafire.com/download/w283nsjuuj9j794/File-Folder.txt
As your config folder is inside of node_modules folder, thus use:
var chgpass = require('config/chgpass');
Explanation:
In tutorial config folder is inside node_modules that way you can directly access it using require('config/chgpass')
But if you put outside of node_modules then you have to give the complete path of the folder from the location you are requiring it. That is in your case: require('../config/chgpass')
I have seen a few different posts about not being able to find local files to open them up whether they be images or data files, but none of the solutions have worked for me. My guess would be there is some configuration I'm missing.
The file I'm looking for is in a folder named "data" on the same level as my app.html and app.ts files.
Here is what I have in app.html, PS I'm also using Ionic2:
<ion-menu (click)='getDepartments()' side='right' type='overlay' [content]="content">
and in the app.ts file I have:
getDepartments() {
this.http.get('/data/data.json')
.map(res => res.json())
.subscribe(
data => this.departments = data,
err => console.log(err),
() => console.log('Random Quote Complete')
);
}
I've tried:
./data/data.json
data/data.json
app/data/data.json
and any other path. And they all return a 404 file not found error. This seems just like growing pains with getting familiar with Angular 2. Thanks in advance
Previous answers have said to put it directly in the www folder to make it available to the app. I would say this is not the best solution as the www folder is excluded using .gitignore in a newly created Ionic2 project.
Instead put it inside the src/assets folder and it will also be made available in App and it will NOT be excluded from the git repo (by default).
Then you can access using: this.http.get('assets/file.json');
You could modify the .gitignore file, but then you may be including other unnecessary files.
I didn't realize that working with Ionic that it compiles everything in the app folder and puts it into the www/build folder. Therefore when I put a path in the uncompiled app folder I didn't realize that the file I'm putting the path in isn't where I think it is.
So I did two things, each worked. I put the files directly in the www file (don't put them in the build file as they will be deleted every time you run ionic serve), and then fix the path accordingly. Or just fix the path knowing that when you look for a file in your app.ts, it needs to exit out of www/build first.
For any anyone who is interested in resolving the same problem. If you are using Angular CLI and you want to make any folder accessible through http as in this case "data" folder.
Go to Angular-CLI.JSON then add "the folder name" which is "data" under apps -> assets
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"data"
],
Is your server able to see the folder '/data'? Make sure your JSON file is located in the same directory as your public/static files.
The topic may seem to be duplicate. Read it completely
I know there are multiple packages available in nodejs to require all the files in a directory.
But I am in a research to require all the files in a folder and use the variables and functions which are exported in each js file. Need to perform this just by requiring the directory name.
For example,
var files = require("./folder");
The folder may contain some files like
File1.js, File2.js, File3.js
I want to use all the variables and functions which are exported in all the js files.
I think there might be some way in the "Package.json" file.
But I am not expert in "Package.json".
Can anyone help me to figure out the senario?
Could you just make an index.js file with the modules and just require that.
From the docs http://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
It is convenient to organize programs and libraries into self-contained directories, and then provide a single entry point to that library. There are three ways in which a folder may be passed to require() as an argument.
The first is to create a package.json file in the root of the folder, which specifies a main module. An example package.json file might look like this:
{ "name" : "some-library",
"main" : "./lib/some-library.js" }
If this was in a folder at ./some-library, then require('./some-library') would attempt to load ./some-library/lib/some-library.js.
This is the extent of Node's awareness of package.json files.
If there is no package.json file present in the directory, then node will attempt to load an index.js or index.node file out of that directory. For example, if there was no package.json file in the above example, then require('./some-library') would attempt to load:
./some-library/index.js
./some-library/index.node