Intern functional tests: module request is missing - node.js

I've tried setting up a minimal test demonstration, but I'm stuck when I try to run tests.
What I get is:
Listening on 0.0.0.0:9000
Starting tunnel...
Error: Failed to load module request from /tmp/local-selenium-intern/request.js (parent: tests/functional)
at <node_modules/intern/node_modules/dojo/dojo.js:757:12>
at <fs.js:207:20>
at Object.oncomplete <fs.js:107:15>
What I expect is that internal modules (such as request doesn't require any explicit configuration for them to load correctly).
I have this test configuration:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.35.0',
'idle-timeout': 30
},
environments: [
{ browserName: 'firefox' },
{ browserName: 'chrome' }
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
loader: {
// TODO: What to add here?
},
suites: [ 'tests/unit' ],
functionalSuites: [ 'tests/functional' ],
excludeInstrumentation: /^(?:tests|node_modules)\//
});
tests/functional.js contains this:
'use strict';
define([
'intern!object',
'intern/chai!assert',
'request'
], function (registerSuite, assert, request) {
registerSuite({
name: 'async demo',
'async test': function () {
var dfd = this.async(1000);
request('http://example.com/test.json').then(dfd.callback(function (data) {
assert.strictEqual(data, 'Hello world!');
}), dfd.reject.bind(dfd));
}
});
});
(An example from interns own documentation.)
The example provided is very basic and can be tested by downloading the code below followed `npm install && npm start``:
https://github.com/mzedeler/local-selenium-intern/tree/request-broken

From looking at your repository, I see you fixed the issue by using the request module from Intern's copy of Dojo. While this works, it's better to use your own copy of Dojo for your tests. Intern (the non-geezer version, at least) doesn't use standard Dojo, and makes no guarantees about the functionality therein. The current release of Dojo (1.10.0) is available through the npm repository, so it's easy to include as a project dependency.
Also, the test config in your project is a bit out of date. Specifically, the webdriver and useSauceConnect options have been replaced by tunnel and tunnelOptions. More information about the changes in Intern 2 is available in the 2.0.0 release notes.

Related

ERR_INVALID_ARG_TYPE running criticalcss with webpack

With the following webpack.mix.js file
const mix = require("laravel-mix");
// Laravel Mix plugins for additional capabilities
require("laravel-mix-purgecss");
require("laravel-mix-criticalcss");
// CSS Plugins
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const presetenv = require("postcss-preset-env");
mix.setPublicPath('../public_html/assets/')
.sass(pkg.paths.src.scss + "master.scss", "css/master.min.css")
.options({
processCssUrls: false,
postCss: [ tailwindcss('./tailwind.config.js') ],
})
.js(pkg.paths.src.js + "site.js", "js/site.min.js")
.sourceMaps()
.browserSync({
proxy: "domain.local",
notify: {
styles: {
top: 'auto',
bottom: '0'
}
},
files: [
"src/scss/*.scss",
"templates/*.twig",
"templates/**/*.twig",
"templates/*.js",
"templates/**/*.js"
]
});
// mix.disableSuccessNotifications();
if (mix.inProduction()) {
mix.webpackConfig({
plugins: [],
})
.criticalCss({
enabled: true,
paths: {
base: 'https://domain.local',
templates: './templates/_inline_css/',
suffix: '.min'
},
urls: [
{ url: '/', template: 'index' },
],
options: {
minify: true,
timeout: 1200000,
},
})
.version();
}
when I run npm run production I get:
98% after emitting HtmlCriticalWebpackPlugin(node:58149) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined.
What's confusing about this is that at one point this was working OK. My list of URLs is longer than what I've displayed above. And the first time I tried it, it successfully output CSS files but I was getting problems with timeouts so started doing a few at a time.
I was able to successfully run it two or three times before the above error appeared and now it won't compile anymore. I even went back and tried the same bundles I'd tried before but it wouldn't work the second time around.
I've also tried a similar set-up using Gulp but get the same error.
Has anyone else ever got this? How did you solve it?

react-boilerplate yarn start:prod This site can’t be reached localhost refused to connect. http://localhost:3000 => https://localhost/

https://github.com/react-boilerplate/react-boilerplate
Description
After running yarn run build,
yarn start:prod
It says it is running on the terminal window, however,
when i go to http://localhost:3000 the url suddenly changes to => https://localhost/ and says
this site can’t be reached localhost refused to connect.
development mode yarn start works fine
Steps to reproduce
I removed ImmutableJS following the guide from one of the issues in react-boilerplate.
I added feathersJS backend, frontend.
I changed babel-loader in webpack.base.babel.js
to
rules: [
{
test: /\.js$/, // Transform all .js files required somewhere with Babel
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: options.babelQuery,
query: {
plugins: [
["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }]
],
},
},
},
I changed the app.js file
// Install ServiceWorker and AppCache in the end since
// it's not most important operation and if main code fails,
// we do not want it installed
if (process.env.NODE_ENV === 'production') {
// require('offline-plugin/runtime').install(); // eslint-disable-line global-require
const runtime = require('offline-plugin/runtime');
runtime.install({
onUpdating: () => {
console.log('SW Event:', 'onUpdating');
},
onUpdateReady: () => {
console.log('SW Event:', 'onUpdateReady');
// Tells to new SW to take control immediately
runtime.applyUpdate();
},
onUpdated: () => {
console.log('SW Event:', 'onUpdated');
// Reload the webpage to load into the new version
window.location.reload();
},
onUpdateFailed: () => {
console.log('SW Event:', 'onUpdateFailed');
}
});
}
Much appreciate your help!
(Add link to a demo on https://jsfiddle.net or similar if possible)
Versions
React-Boilerplate (see package.json): 3.6.0
Node/NPM: v9.11.1
Browser: chrome
I forgot I was using ssl-redirect for heroku deployment.
var sslRedirect = require('heroku-ssl-redirect');
// heroku enable ssl redirect
app.use(sslRedirect()); //heroku https
cheers :)

Jasmine ignoring typescript test files?

This is my first time making a project with Jasmine, and I'm following a tutorial but right off the bat having issues.
I've installed jasmine-node, typings, and typescript. I also ran:
typings install dt~jasmine --save-dev --global
For Jasmine typescript.
Now I have a test file in my ./spec folder that looks like this:
import { async, ComponentFixture, TestBed } from '#angular/core/testing';
import { DatePickerComponent } from '../src/components/via-datepicker.component';
import * as moment from 'moment';
const Moment: any = (<any>moment).default || moment;
describe('DatePickerComponent', () => {
let component: DatePickerComponent;
let fixture: ComponentFixture<DatePickerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DatePickerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DatePickerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should open when clicked', () => {
fixture.debugElement.nativeElement.querySelector('body').click();
fixture.whenStable().then(() => {
expect(component.opened);
});
component.close();
});
describe('While open', () => {
beforeEach(() => {
component.open();
});
describe('Pressing the "Today\'s date" button', () => {
it('should set the value of the picker to the current date and close it', () => {
fixture.debugElement.nativeElement.querySelector('.datepicker-buttons button').click();
expect(Moment().isSame(component.value, 'day') && Moment().isSame(component.value, 'month'));
expect(!component.opened);
});
});
describe('Clicking on a date', () => {
it('should change the value of the picker and close it', () => {
let oldValue: any = component.value;
fixture.debugElement.nativeElement.querySelectorAll('.day')[10].click();
expect(!component.opened);
expect(!component.value.isSame(oldValue));
});
});
});
});
But when I run this command:
node_modules/jasmine-node/bin/jasmine-node spec
I get this result:
Finished in 0 seconds
0 tests, 0 assertions, 0 failures, 0 skipped
So clearly my test file is being ignored. Or maybe I'm missing some library? Would I receive an error message if this were the case? The main issue here is that I'm not being given much direction as to what the issue is, other than Jasmine doesn't seem to "see" the test file for some reason.
Just trying to move forward with my project. Any advice would be greatly appreciated.
It appears as if your test runner doesn't know that you're trying to run typescript tests. Are you using Karma as your test runner? If so, you need to add your Typescript files to your karma.config file and install karma-typescript and configure your karma.config file similar to what is shown below. Pay close attention to the addition to the frameworks, files, and preprocessors sections.
karma.config
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'karma-typescript'],
// list of files / patterns to load in the browser
files: [
{ pattern: "app/tests/**/*.spec.js"}
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"app/tests/**/*.spec.ts": ["karma-typescript"]
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
};

Disable Hapi logs on test environment

I'm using Hapi with Good on a small project and want to disable some logs while testing (process.env.NODE_ENV == 'test').
This is my Good configuration:
reporters: {
console: [{
module: 'good-console',
}, 'stdout']
}
And this is the test output:
➜ npm test
Index Route
✓ is ok
160622/214344.247, [response] http://paulodiovani-ideapad:3001: get / {} 200 (27ms)
How can I disable all logs, except error?
Can you post your good configuration? you probably want something like:
reporters: {
console: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [{error: '*'}]
},
{
module: 'good-console'
},
'stderr']
}

Working with intern.js and browserstack, access the remote browser environment

I'm trying to perform a basic functional test:
define([
'intern!object',
'intern/chai!assert',
'../Request',
'require'
], function (registerSuite, assert, Request, require) {
var request,
url = 'https://github.com/theintern/intern';
registerSuite({
name: 'demo',
'submit form': function () {
return this.remote
.get(require.toUrl('./fixture.html'))
.findById('operation')
.click()
.type('hello, world')
.end()
.findById('submit')
.click()
.end()
.setFindTimeout(Infinity)
.findById('result')
.setFindTimeout(0)
.text()
.then(function (resultText) {
assert.ok(resultText.indexOf(
'"hello, world" completed successfully') > -1,
'On form submission, operation should complete successfully');
});
}
});
});
(Example from the intern.js documentation)
https://github.com/theintern/intern/wiki/Writing-Tests-with-Intern
My intern.js configuration file is as followed:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.41.0'
},
environments: [
{ browserName: 'chrome'}
],
maxConcurrency: 3,
tunnel: "BrowserStackTunnel",
webdriver: {
host: 'http://hub.browserstack.com/wd/hub',
username: 'XXXXX',
accessKey: 'XXXXX'
},
useSauceConnect: false,
loader: {
packages: [
{
name: "dojo",
location: 'vendor/dojo'
}
]
},
suites: [ "tests/test" ],
excludeInstrumentation: /^(?:tests|node_modules)\//
});
When I run my test, it seems that the connection is being made with browserstack, but my test keep failing:
-> ./node_modules/.bin/intern-runner config=tests/intern
Listening on 0.0.0.0:9000
Starting tunnel...
BrowserStackLocal v2.2
Ready
Initialised chrome 35.0.1916.114 on XP
Test main - index - test FAILED on chrome 35.0.1916.114 on XP:
TypeError: Cannot read property 'get' of null
at Test.registerSuite.test <tests/test.js:11:17>
at Test.run <__intern/lib/Test.js:154:19>
at <__intern/lib/Suite.js:212:13>
at signalListener <__intern/node_modules/dojo/Deferred.js:37:21>
at Promise.then.promise.then <__intern/node_modules/dojo/Deferred.js:258:5>
at <__intern/lib/Suite.js:211:46>
I assumed that the WebDriver is not loaded, how may I access the remote browser environment inside my functional test?
Only functional tests interact with a WebDriver client and have a remote property. In your config, include your test suite in the functionalSuites array, not suites.
Note that the webdriver property is no longer used, so if you want to specify your username and access key in the config file you should use tunnelOptions instead.
tunnelOptions: {
username: <username>,
accessKey: <accessKey>
}
The tunnel knows the proper hostname to use by default, so you don't need to provide that.

Resources