I'm trying to setup Intern to run with PhantomJS on a Windows 7 machine
Since now my setup is as follows:
demo test root/unit/tests/phantom.js:
define([
'intern!object',
'intern/chai!assert'
], function(registerSuite, assert) {
registerSuite({
name: 'PhantomTest',
'dummy': function () {
assert(true, "Works!");
}
});
});
Configuration file root/unit/intern.config.js:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.30.0'
},
environments: [
{
browserName: 'phantom'
}
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
// used here
loader: {
},
suites: [ 'unit/tests/phantom.js' ],
functionalSuites: [ /* 'myPackage/tests/functional' */ ],
excludeInstrumentation: /^tests\//
});
By running this test and config in a browser it just works.
To run Intern with PhantomJS i execute:
phantomjs --webdriver=4444
And:
cd root
node node_modules\intern\runner.js config=unit/intern.config
The console running Phantomjs then returns:
[INFO - 2013-07-01T21:29:07.253Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 42ba5b50-e295-11e2-86f7-e331eb8b922d
While the other one outputs the following message without any further log:
Defaulting to "runner" reporter
Listening on 0.0.0.0:9000
Initialised phantomjs 1.9.1 on windows-7-32bit
Any hint on what i'm missing?
The reason for this is https://github.com/ariya/phantomjs/issues/10522; phantomjs is using an extremely old version of JavaScriptCore that has no Function.prototype.bind. Your best bet at this moment is to switch to using the geezer version of Intern, which should work properly in this older environment.
Related
We have a react app that we were building using webpack, but are trying to migrate into Vite the significantly lower build times.
We've successfully refactored our build code to use vite, where builds and dev server run successfully when we run them locally. However, whenever we deploy to heroku, and the build script starts... the build simply stalls on the while transforming the js files.
Log Below:
...
2023-02-05T19:26:35.377Z vite:resolve 2.32ms css_variables/colors.css -> /tmp/build_38ed17db/src/css/css_variables/colors.css
2023-02-05T19:26:35.861Z vite:resolve 0.33ms css_variables/durations.css -> /tmp/build_38ed17db/src/css/css_variables/durations.css
2023-02-05T19:26:36.059Z vite:resolve 0.12ms css_variables/sizes.css -> /tmp/build_38ed17db/src/css/css_variables/sizes.css
2023-02-05T19:26:36.090Z vite:resolve 0.12ms css_variables/indices.css -> /tmp/build_38ed17db/src/css/css_variables/indices.css
2023-02-05T19:26:36.175Z vite:resolve 0.22ms index.css -> /tmp/build_38ed17db/src/css/index.css
2023-02-05T19:26:36.210Z vite:resolve 0.12ms nav_bar.css -> /tmp/build_38ed17db/src/css/nav_bar.css
2023-02-05T19:26:36.340Z vite:resolve 0.19ms other_pages/auth_page.css -> /tmp/build_38ed17db/src/css/other_pages/auth_page.css
2023-02-05T19:26:36.460Z vite:resolve 0.37ms other_pages/page.css -> /tmp/build_38ed17db/src/css/other_pages/page.css
2023-02-05T19:26:36.724Z vite:resolve 0.19ms other_pages/simple_pages.css -> /tmp/build_38ed17db/src/css/other_pages/simple_pages.css
2023-02-05T19:26:37.009Z vite:resolve 0.18ms superadmin/superadmin_page.css -> /tmp/build_38ed17db/src/css/superadmin/superadmin_page.css
2023-02-05T19:26:37.133Z vite:resolve 0.16ms other_pages/pricing_calculator_page.css -> /tmp/build_38ed17db/src/css/other_pages/pricing_calculator_page.css
2023-02-05T19:26:37.954Z vite:resolve 0.20ms other_pages/project_portfolio_page.css -> /tmp/build_38ed17db/src/css/other_pages/project_portfolio_page.css
I've been scratching my head for days, because there are no log outputs for an error having occurred, and I've run out of options for searching online for solutions to this problem.
Our config looks as follows:
import { defineConfig, loadEnv } from "vite";
import * as path from "path";
import { fileURLToPath } from "url";
import react from "#vitejs/plugin-react";
import rollupNodePolyFill from "rollup-plugin-polyfill-node";
import { NodeModulesPolyfillPlugin } from "#esbuild-plugins/node-modules-polyfill";
import svgr from "vite-plugin-svgr";
import inject from "#rollup/plugin-inject";
import progress from 'vite-plugin-progress'
import dns from "dns";
dns.setDefaultResultOrder("verbatim");
export default defineConfig(({ command, mode, ssrBuild }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
base: "/",
root: "./",
resolve: {
alias: {
"react-native": "react-native-web",
"src": path.resolve(path.dirname(fileURLToPath(import.meta.url)), "./src"),
util: "rollup-plugin-node-polyfills/polyfills/util",
sys: "util",
events: "rollup-plugin-node-polyfills/polyfills/events",
stream: "rollup-plugin-node-polyfills/polyfills/stream",
path: "rollup-plugin-node-polyfills/polyfills/path",
querystring: "rollup-plugin-node-polyfills/polyfills/qs",
punycode: "rollup-plugin-node-polyfills/polyfills/punycode",
url: "rollup-plugin-node-polyfills/polyfills/url",
string_decoder:
"rollup-plugin-node-polyfills/polyfills/string-decoder",
http: "rollup-plugin-node-polyfills/polyfills/http",
https: "rollup-plugin-node-polyfills/polyfills/http",
os: "rollup-plugin-node-polyfills/polyfills/os",
assert: "rollup-plugin-node-polyfills/polyfills/assert",
constants: "rollup-plugin-node-polyfills/polyfills/constants",
_stream_duplex:
"rollup-plugin-node-polyfills/polyfills/readable-stream/duplex",
_stream_passthrough:
"rollup-plugin-node-polyfills/polyfills/readable-stream/passthrough",
_stream_readable:
"rollup-plugin-node-polyfills/polyfills/readable-stream/readable",
_stream_writable:
"rollup-plugin-node-polyfills/polyfills/readable-stream/writable",
_stream_transform:
"rollup-plugin-node-polyfills/polyfills/readable-stream/transform",
timers: "rollup-plugin-node-polyfills/polyfills/timers",
console: "rollup-plugin-node-polyfills/polyfills/console",
vm: "rollup-plugin-node-polyfills/polyfills/vm",
zlib: "rollup-plugin-node-polyfills/polyfills/zlib",
tty: "rollup-plugin-node-polyfills/polyfills/tty",
domain: "rollup-plugin-node-polyfills/polyfills/domain",
buffer: "rollup-plugin-node-polyfills/polyfills/buffer-es6",
process: "rollup-plugin-node-polyfills/polyfills/process-es6",
"node-modules-polyfills:buffer": "buffer",
"node-modules-polyfills:string_decoder": "string_decoder"
}
},
server: {
port: 3001
},
// Env vars aren't exposed by default so we need to opt-in by prefix
envPrefix: [
"REACT_APP_",
"NODE_ENV"
],
define: {
__APP_ENV__: env.APP_ENV,
"process.env": env,
VITE: true
},
build: {
target: "modules",
minify: "esbuild",
manifest: true,
sourcemap: true,
outDir: "build",
rollupOptions: {
cache: true,
plugins: [
inject({
exclude: ["node_modules/library/**/*.js"]
}),
rollupNodePolyFill()
],
output: {
manualChunks(id) {
if (id.includes('recharts')) {
return 'recharts';
}
}
}
},
commonjsOptions: {
transformMixedEsModules: true,
esmExternals: "auto"
}
},
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis"
},
plugins: [
NodeModulesPolyfillPlugin()
]
}
},
plugins: [
react(),
svgr(),
progress()
]
};
});
Our heroku server sets YARN_PRODUCTION to true, and uses the YARN_CACHE but we've attempted removing those to no avail.
I've followed just about every guide to fix this problem I can find online, and it still just wont work.
I'm under the impression that perhaps the build is running out of memory (our application is quite large), but usually when that is the case, heroku would notify us in the logs.
If there is any significant details that would be helpful in attempting to help, please let me know, and I'll do my best to provide them. But I am seriously confused at what is going wrong.
some tips :
this line is only relevant for dev mode server , try to comment it
dns.setDefaultResultOrder("verbatim");
I think the process try to apply polyfills to existing polyfills....
Is there any way to debug Webdriverio tests using nodeJS and WebStorm?
I've found some conclusion here and this is actually my problem: Run WebdriverIO tests via Mocha in WebStorm
But this solution doesn't fit to my problem now;
I've set up Babel to compile my BDD tests
I've set tests.config.js
module.exports = { maxInstances: 1,
capabilities: [{ browserName: 'chrome' }],
execArgv: ['--inspect'] : [],
specs: ['**/some/spec.js']
mochaOpts: {
ui: 'bdd',
compilers: ['js:#babel/register'],
timeout: 150000
} }
and babel.conf.js
module.exports = {
presets: [
['#babel/preset-env', {
targets: {
node: 12
}
}]
]
}
then I've created nodeJS configuration like it said here at answer: Run WebdriverIO tests via Mocha in WebStorm
Set breakpoint at test
describe("test", function(){
it ("this is a BDD test",
function(){
breakpoint here>> do_some_action();
})
})
But when I try to launch my tests in debug mode nothing happens and I see "connnected to localhost:port" message. and I can't go to breakpoint; there are no errors;
there was problem with a wdio.conf.js file. If you don't set specs file >> there aren't no errors. But launching is incorrect. I've set config like this:
module.exports =
{
capabilities: [{
maxInstances: 6,
browserName: 'chrome',
baseUrl: "some-url/",
browserVersion: '67.0'}]
specs: [
'./this/is/spec.js']
mochaOpts: {
ui: 'bdd',
require: ['#babel/register'],
timeout: 150000
},
And debug works after this. It's not too har as I though :) If there are some questions - > I'm glad o answer
I have a setup of my angular-app and a separate selenium server as docker-compose setup
my protractor setting looks like this
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: false,
baseUrl: 'http://user-frontend:4200/',
seleniumAddress: 'http://selenium:4444/wd/hub',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
now I run the command to run the end2end tests using protractor:
ng e2e --no-serve
All my tests are failing, and when I debug the selenium server and take screenshots, I see it is trying to connect to itself (localhost) instead of back to the application host baseUrl: 'http://user-frontend:4200/',
any Idea what I am doing wrong here?
Are you sure that browser.baseUrl (or browser.get()) is not set elsewhere?
My tests are throwing the following error. It used to run fine before. Please advise.
My Config file:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
allScriptsTimeout: 20000,
baseUrl: 'https://mylink/#/',
// frameworks to use
frameworks: ['jasmine'],
// Capabilities to be passed to the webdriver instance.
multiCapabilities: [{
'browserName': 'chrome'
//}, {
// 'browserName': 'firefox'
//
}],
// Spec patterns are relative to the current working directory.
specs: [
'tests/HomePage.js'
],
onPrepare: function() {
browser.driver.manage().window().maximize();
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true. true));
},
jasmineNodeOpts: {
showColors: true
}
}
My Spec file:
// spec.js
describe('MyTest homepage', function() {
var ptor;
require('protractor-linkuisref-locator')(protractor);
beforeEach(function() {
browser.ignoreSynchronization = true;
ptor = protractor.getInstance();
browser.rootEl = 'div';
//browser.driver.manage().window().setSize(1280, 1024);
browser.debugger();
});
it('Should enter homepage url and credentials', function() {
browser.get('/#/');
element(by.name('userName')).sendKeys('');
element(by.name('password')).sendKeys('');
element(by.xpath("//button[#class=' btn orange small wide']")).click();
});
it('Should the title contain', function() {
expect(browser.getTitle()).toEqual('');
});
it('Should click on the PowerGuide', function() {
element(by.linkUiSref('locator')).click();
ptor.sleep(100);
//expect(ptor.getCurrentUrl(locator)).toEqual('');
});
it('Should click on Month', function() {
element(by.id('month-tab')).click();
ptor.sleep(100);
});
//it('Should load the images', function() {
// element(by.css('.pure-u-1-2')).click();
//var icons = element.all(by.css('.pure-u-1-2')).click();
//icons.first().click();
//});
});
This is the error I am getting.
seleniumProcess.pid: 1380
14:43:45.163 INFO - Launching a standalone server
Setting system property webdriver.chrome.driver to C:\Users\sramamoorthy\AppData\Roaming\npm\node_modules\protractor\sel
enium\chromedriver.exe
14:43:45.342 INFO - Java: Oracle Corporation 25.40-b25
14:43:45.342 INFO - OS: Windows 7 6.1 amd64
14:43:45.373 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
14:43:45.597 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
14:43:45.597 INFO - Version Jetty/5.1.x
14:43:45.597 INFO - Started HttpContext[/selenium-server,/selenium-server]
14:43:45.779 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#23223dd8
14:43:45.781 INFO - Started HttpContext[/wd,/wd]
14:43:45.781 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
14:43:45.781 INFO - Started HttpContext[/,/]
14:43:45.789 INFO - Started SocketListener on 0.0.0.0:4444
14:43:45.789 INFO - Started org.openqa.jetty.jetty.Server#133314b
14:44:41.384 INFO - Executing: [new session: Capabilities [{count=1, browserName=chrome}]])
14:44:41.399 INFO - Creating a new session for Capabilities [{count=1, browserName=chrome}]
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 44385
Only local connections are allowed.
14:44:43.309 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome}]]
14:44:43.567 INFO - Executing: [set script timeoutt: 20000])
14:44:43.584 INFO - Executing: [delete session: 64c8dac4-559f-416d-b77b-78c5184b6538])
14:44:43.590 INFO - Done: [set script timeoutt: 20000]
14:44:45.303 INFO - Done: [delete session: 64c8dac4-559f-416d-b77b-78c5184b6538]
Test Error: This is the error I am getting where i am calling the Conf.js file from
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: undefined is not a function
at
at Object.exports.run (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\frameworks\jasmine.js:6
2:17)
at C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:326:35
at _fulfilled (C:\Users\sr\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:
826:30)
at Promise.promise.promiseDispatch (C:\Users\ppData\Roaming\npm\node_modules\protractor\node_modules\q
\q.js:759:13)
[launcher] Process exited with error code 100
There is a typo inside onPrepare():
onPrepare: function() {
browser.driver.manage().window().maximize();
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true. true));
// HERE^
},
You meant instead:
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true));
Error: TypeError: undefined is not a function
at
at Object.exports.run (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\frameworks\jasmine.js:6
The error is from the library. I think you might missed some dependencies that the library requires.
Removing this line fixed a similar problem for me:
seleniumAddress: 'http://localhost:4444/wd/hub',
Premise: my app works perfectly, but anyway I decided to imoplement units tests.
My test, that check if a service given object is defined or not fails.
here is my service code:
//app/components/lib/search.js
angular.module("search", ["lazyLoad", "httpInterceptor"])
.service("SearchObject", ['$rootScope', '$location', 'Globals', function ($rootScope, $location, Globals) {
'use strict';
var obj,
SearchObjectPrototype = {};
SearchObjectPrototype.clone = function (source) {
var prop;
for (prop in this) {
if (this.hasOwnProperty(prop)) {
this[prop] = source[prop] || null;
}
}
};
//Definizione SearchObject
obj = Object.create(SearchObjectPrototype, {
q : {value: null, writable: true, enumerable: true},
max_id : {value: null, writable: true, enumerable: true},
next_results : {value: null, writable: true, enumerable: true},
query_debug : {value: null, writable: true, enumerable: true}
});
Object.preventExtensions(obj);
this.getInstance = function () {
return obj;
};
}])
Here is my test code:
console.log(1);
describe('search module', function() {
console.log(2);
beforeEach(module('search'));
describe('SearchObject test', function() {
console.log(3);
var SearchObject;
beforeEach(inject(function(_SearchObject_){
console.log(4);
// The injector unwraps the underscores (_) from around the parameter names when matching
SearchObject = _SearchObject_;
}));
it('should evaluate the injected SearchObject', function (){
console.log(5);
expect(SearchObject).toBeDefined()
});
});
});
Here is my karma.conf.js
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2015-10-20 using
// generator-karma 1.0.0
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
// as well as any additional frameworks (requirejs/chai/sinon/...)
frameworks: [
"jasmine"
],
// list of files / patterns to load in the browser
files: [
// bower:js
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js',
'bower_components/Chart.js/Chart.js',
'bower_components/angular-chart.js/dist/angular-chart.js',
'bower_components/bootstrap-sass/assets/javascripts/bootstrap.js',
'bower_components/angular-mocks/angular-mocks.js',
// endbower
"app/components/lib/search.js",
// "test/mock/**/*.js",
"test/spec/search.js"
],
// list of files / patterns to exclude
exclude: [
],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
"PhantomJS"
],
// Which plugins to enable
plugins: [
"karma-chrome-launcher",
"karma-phantomjs-launcher",
"karma-jasmine"
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
Here my Karma output
Running "karma:unit" (karma) task
11 02 2016 11:55:43.447:INFO [karma]: Karma v0.13.19 server started at http://lo
calhost:8080/
11 02 2016 11:55:43.474:INFO [launcher]: Starting browser PhantomJS
11 02 2016 11:55:46.510:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on s
ocket /#OphIJTNigEfxY1NIAAAA with id 56068342
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 1
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 2
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 3
LOG: 5
PhantomJS 2.1.1 (Windows 8 0.0.0) test sul modulo search SearchObject test shoul
d evaluate the injected SearchObject FAILED
C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular/angular.j
s:4459:53
forEach#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular/a
ngular.js:340:24
loadModules#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angul
ar/angular.js:4419:12
createInjector#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/an
gular/angular.js:4344:22
workFn#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular-mo
cks/angular-mocks.js:2428:60
**Expected undefined to be defined.**
C:/Users/Rick/Sviluppo/socialsider-fe/test/spec/search.js:19:45
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.043 se
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.019 secs
/ 0.043 secs)
As you can see log(4), which is in the same block of SearchObject assignement, didn't get called. The object is undefined and the test fails.
Anyone can explain me why? It can be a dependency problem?
I have found that you need to inject your services/factories yourself:
beforeEach(function() {
module('search'));
inject(function(_SearchObject_) {
SearchObject = _SearchObject_;
});
});
That should make the service available to the tests. I just went back and spot checked some of my own tests and saw that this was the common piece all of my factory and service tests had.
Update:
After further review, there are some really odd things going on here and possibly multiple issues that need to be resolved. I don't have all of your dependency libraries and the angular module wouldn't load at all in the tests without mocking or removing lazyLoad and httpInterceptor. I'm going to assume that isn't your issue though and the module loads. After that once I mocked out Globals it loads just fine.
So in short, be sure you are properly providing lazyLoad, httpInterceptor, and Globals to the test, either with the actual code or through mocking, and the test passes. At least for me it does.