I have a created a new application JHipster and without any modification, I am not able to package it.
Here is my .yo-rc.json
{
"generator-jhipster": {
"promptValues": {
"packageName": "testbug",
"nativeLanguage": "en"
},
"jhipsterVersion": "5.1.0",
"applicationType": "monolith",
"baseName": "testBugJhipster",
"packageName": "testbug",
"packageFolder": "testbug",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": "spring-websocket",
"databaseType": "sql",
"devDatabaseType": "h2Memory",
"prodDatabaseType": "mysql",
"searchEngine": "elasticsearch",
"messageBroker": "kafka",
"serviceDiscoveryType": "eureka",
"buildTool": "maven",
"enableSwaggerCodegen": true,
"jwtSecretKey": "a1643dc27d4bad4c20782e29fe5491fc3ecdf5e5",
"clientFramework": "angularX",
"useSass": true,
"clientPackageManager": "yarn",
"testFrameworks": [
"gatling",
"cucumber",
"protractor"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en",
"fr"
]
}
}
To package, I use
./mvnw -Pprod package
At first, I had this error :
[INFO] Running 'yarn run webpack:test' in /home/korrident/testBugJhipster
[INFO] yarn run v1.6.0
[INFO] $ yarn run test
[INFO] $ yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js
[INFO] $ tslint --project tsconfig.json -e 'node_modules/**'
[ERROR] No valid rules have been specified
[ERROR] FAIL src/test/javascript/spec/app/shared/login/login.component.spec.ts
[ERROR] ● Test suite failed to run
[ERROR]
[ERROR] SecurityError: localStorage is not available for opaque origins
[ERROR]
[ERROR] at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)
[ERROR] at Array.forEach (<anonymous>)
[ERROR]
based on this SO :
client side tests fail using jhipster 5.1.0
I added at the end of src/test/javascript/jest.conf.js
testEnvironment: "node",
testURL: "http://localhost/"
But now, I have this error
[INFO] $ yarn run test
[INFO] $ yarn run lint && jest --coverage --logHeapUsage -w=2 --config src/test/javascript/jest.conf.js
[INFO] $ tslint --project tsconfig.json -e 'node_modules/**'
[ERROR] No valid rules have been specified
[ERROR] FAIL src/test/javascript/spec/app/admin/health/health.component.spec.ts
[ERROR] ● Test suite failed to run
[ERROR]
[ERROR] ReferenceError: XMLHttpRequest is not defined
[ERROR]
[ERROR] at patchXHR (node_modules/zone.js/dist/zone.js:2926:39)
[ERROR] at node_modules/zone.js/dist/zone.js:2919:5
[ERROR] at Function.Object.<anonymous>.Zone.__load_patch (node_modules/zone.js/dist/zone.js:84:33)
[ERROR] at node_modules/zone.js/dist/zone.js:2917:6
[ERROR] at Object.<anonymous>.FUNCTION (node_modules/zone.js/dist/zone.js:9:65)
[ERROR] at Object.<anonymous> (node_modules/zone.js/dist/zone.js:12:2)
[ERROR] at Object.<anonymous> (node_modules/jest-preset-angular/setupJest.js:5:1)
[ERROR]
Except jest.conf.js, git diff show no other changes from the init commit.
I tried to install xmlhttprequest#^1.8.0 but no change in jest result.
This question is not urgent because I can disable the test, but I can't allow it for too long.
Thank you #jared-smith for solving it.
Correct configuration in src/test/javascript/jest.conf.js
module.exports = {
preset: 'jest-preset-angular',
setupTestFrameworkScriptFile: '<rootDir>/src/test/javascript/jest.ts',
coverageDirectory: '<rootDir>/target/test-results/',
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json'
},
__TRANSFORM_HTML__: true
},
moduleNameMapper: {
'app/(.*)': '<rootDir>/src/main/webapp/app/$1'
},
reporters: [
'default',
[ 'jest-junit', { output: './target/test-results/jest/TESTS-results.xml' } ]
],
testResultsProcessor: 'jest-sonar-reporter',
transformIgnorePatterns: ['node_modules/(?!#angular/common/locales)'],
testMatch: ['<rootDir>/src/test/javascript/spec/**/+(*.)+(spec.ts)'],
rootDir: '../../../',
//Path generated code
//To correct SecurityError: localStorage
testEnvironment: "jsdom",
testURL: "http://localhost/"
};
Packaging is now working fine.
(Shouldn't this configuration be commited in jhipster ?)
Related
I have an Angular App that doesn't seem to build with the prod configuration. I get the following error:
Index html generation failed.
undefined:9:219187: property missing ':'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! JI.Infopool.WebApp#0.0.0 build: `ng build --outputHashing=all "--configuration=prod"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the JI.Infopool.WebApp#0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
The normal build works fine and I don't think that I changed any of the run configurations. I couldn't find anything useful in the log file either. Here's the config in the angular.json file:
"prod": {
"baseHref": "/myApp/",
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
Just change `angular.json' file like this:
"configurations": {
"production": { // <=
"optimization": { //<= add this
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
}
},
"budgets": [...]
there are some reasons may not generate the index file
cause of minificaion on of errored css and script files or you may access the commonjs file. or external files like google fonts all are require internet at build time.
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": true
},
"fonts": true
}
please refer this link for more details
https://angular.io/guide/workspace-config#optimization-configuration
When Jest.js encounters import.meta in the code, I get an error:
FAIL testFile.test.ts
● Test suite failed to run
testFile.ts:40:10 - error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.
40 return import.meta?.env as EnvironmentalVariablesType
I have installed the following babel related packages:
// package.json
"devDependencies": {
"#babel/core": "^7.16.5",
"#babel/preset-env": "^7.16.5",
"#babel/preset-typescript": "^7.16.5",
"#vitejs/plugin-react-refresh": "1.3.6",
"babel-jest": "^27.4.5",
"jest": "27.3.1",
"jest-environment-jsdom-global": "3.0.0",
"react": "17.0.1",
"ts-jest": "27.0.7",
"typescript": "4.1.3",
"vite": "2.6.14"
"dependencies": {
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"babel-preset-vite": "^1.0.4",
I've setup babel.config.js as follows:
module.exports = {
plugins: [ 'babel-plugin-transform-vite-meta-env' ],
presets: [
[
'#babel/preset-env',
{ targets: { node: 'current' } },
],
[ '#babel/preset-typescript' ],
[ 'babel-preset-vite' ],
],
}
and my vite.config.js:
import { defineConfig } from 'vite'
import reactRefresh from '#vitejs/plugin-react-refresh'
import replace from '#rollup/plugin-replace'
// https://vitejs.dev/config/
export default defineConfig( {
base: '/time/',
server: {
port: 9000,
},
plugins: [
reactRefresh(),
replace( {
'process.env.NODE_ENV': JSON.stringify( 'development' ),
'process.env.SHOW_DEV_TOOLS': JSON.stringify( 'true' ),
} ),
],
} )
Tried
set module in tsconfig.json to es2020, esnext, or system
None of these cleared or changed the terminal error.
Is there some misconfiguration above that is preventing Jest from properly running babel?
In tsconfig.json, try setting the compilerOptions as so:
{
"compilerOptions": {
"module": "es2022",
"moduleResolution": "Node"
},
...
}
Install vite-plugin-environment plugin (https://www.npmjs.com/package/vite-plugin-environment)
Create .env file in your project root folder near package.json
provide your env variables in .env files
change all your import.meta.env.YOUR_VAR to process.env.YOUR_VAR
open vite.config.ts and list the vite-plugin-environment:
import EnvironmentPlugin from 'vite-plugin-environment';
...
plugins: [
react(),
...
EnvironmentPlugin('all')
]
Jest will understand process.env.YOUR_VAR, so if you change all your import.meta.env.YOUR_VAR to process.env.YOUR_VAR your test will pass without import.meta.env error
This article helped me for setting up Jest in my Vite project.
You can use the following command to run the test as per the jest documentation along with setting allowSyntheticDefaultImports to "true" in ts config file, these two changes solved the error for me.
yarn NODE_OPTIONS=--experimental-vm-modules npx jest
or
npm NODE_OPTIONS=--experimental-vm-modules npx jest
Ensure you have the relevant modules installed as per this. This article, have proper ts, jest and babel config added. (I have shared my config files for anyone who comes across this error. This article came in pretty handy to know about initial set-up requirements.)
//tsconfig.json
{
"compilerOptions": {
"target": "ES2020", /* Specify ECMAScript target version: '' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"allowJs": true, /* Allow javascript files to be compiled. */
"allowSyntheticDefaultImports": true,
"strict": true, /* Enable all strict type-checking options. */
/* Module Resolution Options */
"moduleResolution": "Node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "src", /* Base directory to resolve non-absolute module names. */
"types": [
"jest"
], /* Type declaration files to be included in compilation. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"include": [
"src/**/*.ts",
"./src/**/*.js"
],
"exclude": [
"node_modules"
],
}
//babel.config.js
export default api => {
const isTest = api.env('test');
// You can use isTest to determine what presets and plugins to use.
return {
presets: [
[
'#babel/preset-env',
'#babel/preset-typescript',
{
'targets': {
'node': 'current',
},
},
]
],
};
};
//jest.config.js
/** #type {import('ts-jest/dist/types').InitialOptionsTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 20000, //to resolve timeout error
roots: ['src'],
modulePaths: ['node_modules', '<rootDir>/src'],
testPathIgnorePatterns: [
'<rootDir>/node_modules/', "/__utils"
],
moduleDirectories: [
"src"
],
transform: {
"^.+\\.js?$": "babel-jest",
"^.+\\.ts?$": "ts-jest"
},
transformIgnorePatterns: [""], // you can add any module that you do not want to transform, The first pattern will match (and therefore not transform) files inside /node_modules.
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|tsx?)$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
testEnvironment: "node",
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
},
globals: {
"ts-jest": {
"useESM": true
}
},
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
}
};
I switched from jest to vitest, which got rid of this error.
No changes to the test code were necessary.
For reference, this is my vitest.config.js:
import { defineConfig } from 'vite';
export default defineConfig({
test: {
globals: true,
environment: 'jsdom'
}
});
I got this log when I run yarn test.
I've tried to delete node_modules, reinstall all the dependencies and run yarn test --no-cache, but it doesn't work.
yarn run v1.22.10
$ jest --coverage
PASS __test__/src/App.test.ts
√ test1 (2 ms)
Running coverage on untested files...Failed to collect coverage from D:\svn-frontend-admin\src\App.vue
ERROR: Unexpected token ] in JSON at position 6179
STACK: SyntaxError: Unexpected token ] in JSON at position 6179
These are my config files
// jest.config.js
module.exports = {
......
preset: 'ts-jest',
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js,ts,vue}', 'src/*.{ts,vue}'],
coverageReporters: ['clover'],
moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'],
transform: {
'.*\\.(vue)$': 'vue-jest',
'^.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': require.resolve('jest-transform-stub'),
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.jsx?$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!(#babel/runtime-corejs3/helpers/esm/.*)|(vue/dist/.*))'
],
......
};
I am trying to automate a simple test case using Nightwatch framework of validating a login. I have followed the steps mentioned on : https://www.softwaretestingmaterial.com/browser-automation-with-nightwatch-and-selenium/
The problem arises when I execute the command node nightwatch tests/bing_test.js in node.js command prompt which results in a error message.
Below is my nightwatch.json configs :
{
"src_folders": ["tests"],
"output_folder": "reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": true,
"server_path": "./lib/selenium-server-standalone-3.8.1.jar",
"log_path": "./reports",
"host": "127.0.0.1",
"port": 4445,
"cli_args": {
"webdriver.chrome.driver": "./lib/drivers/chromedriver.exe",
"webdriver.gecko.driver": "./lib/drivers/geckodriver.exe",
"webdriver.edge.driver": "./lib/drivers/MicrosoftWebDriver.exe"
}
},
"test_settings": {
"default": {
"launch_url": "http://localhost",
"selenium_port": 4445,
"selenium_host": "localhost",
"silent": true,
"screenshots": {
"enabled": true,
"path": "./reports/screenshots"
},
"desiredCapabilities": {
"browserName": "chrome",
"marionette": true,
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome"
}
},
"firefox": {
"desiredCapabilities": {
"browserName": "firefox"
}
},
"edge": {
"desiredCapabilities": {
"browserName": "MicrosoftEdge"
}
}
}
}
Error Message :
[Bing Test] Test Suite
======================
Response 500 POST /wd/hub/session (363ms)
{ value:
{ error:
[ "Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'",
"System info: host: 'PDC2LAP-7173253', ip: '192.168.43.196', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'",
'Driver info: driver.version: unknown' ],
message: 'Unable to create new service: ChromeDriverService' },
status: 33 }
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
_________________________________________________
TEST FAILURE: 1 error during execution 0 tests failed, 0 passed. 2.886s
× bing_test
An error occurred while retrieving a new session: "Unable to create new service: ChromeDriverService"
at endReadableNT (_stream_readable.js:1129:12)
at processTicksAndRejections (internal/process/next_tick.js:76:17)
SKIPPED:
- Bing search test
I have tried to debug the issue by going through the comments on GIT forum by setting "webdriver.chrome.driver": "" and "start_process": false, but none of the two worked.
ChromeDriver Version - v72
Selenium Standalone Jar - 3.8.1
Please feel free to guide me to any existing answer/documentation that persists for this issue.
Just I did my web pack upgrade from 2.x to 4.x. By doing npm install i was getting the following error
Module not found: Error: Can't resolve 'babel-loader'
Following the github thread , i added the following lines in webpack.config.json
resolveLoader: { root: path.join(__dirname, 'node_modules') }
But i got the following error ,
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.resolveLoader has an unknown property 'modulesDirectories'. These properties are valid: object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
babel-loader version is 7.1.4 . Webpack upgrade has introduced this error. Any suggestions on this?
Just install the module:
npm install babel-loader
or
yarn add babel-loader
I got this problem fixed by running the above command.
Aren't you install this "babel-loader"
https://www.npmjs.com/package/babel-loader
module: {
rules: [{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src/js'),
],
loader: "babel-loader",
options: {
presets: ["es2015"],
plugins: [
["babel-plugin-root-import", {
"rootPathSuffix": "src/js"
}],
[
"transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
],
"transform-object-assign", "transform-function-bind"
]
},
// options for the loader
}}