I'm building an Express.js API and I'm using mocha and supertest for testing.
However, take a look at this:
root path
GET / 200 5.789 ms - 19
✓ returns 200 status code
GET / 200 0.787 ms - 19
✓ returns json mime type
GET / 200 0.382 ms - 19
✓ contains the package version
I want to get rid of the GET / 200 log so it can look like this:
root path
✓ returns 200 status code
✓ returns json mime type
✓ contains the package version
Any ideas?
[Solved] The output was generated from morgan logger.
The solution was to wrap the middleware like this:
if (app.get('env') === 'development') {
app.use(logger('dev'));
}
Related
In my project we had Jest running just fine and as far as I know no test dependencies were changed. When tests would fail it would log out the details of what was expected versus what was received. But if I have a failing test now (or try to make it fail like the following example) all I get is an error around pretty-format options:
when provided no parameters other than text › default values are set correctly
pretty-format: Unknown option "maxWidth".
48 |
49 | it('default values are set correctly', async () => {
> 50 | expect(element.variant).toBe('primarzy');
It should be telling me that it expected "primarzy" (misspelled on purpose) but got "primary". This is happening no matter which test suite has a failed test.
So for anyone else who encounters this, apparently different packages in my test dependencies were trying to run different versions of pretty-format breaking failed test output. The fix for me was just manually installing pretty-format:
npm i pretty-format --save-dev
Everything works fine after that.
I recently cloned, ran npm install and npm run test for a test Cafe project and I immediately got the following error:
Increase the value of the "pageRequestTimeout" variable, enable the "retryTestPages" option, or use quarantine mode to perform additional attempts to execute this test.
Error details:
Failed to find a DNS-record for the resource at "http://localhost:3000/".
Browser: Chrome 97.0.4692.71 / macOS 10.15.7
23 | async getLoginValidationIssue() {
24 | return Selector('[data-cy=failed-auth]')
25 | }
26 |
27 | async login(username, pwd) {
> 28 | await t.typeText('input[name=email]', username)
29 | await t.typeText('input[name=password]', pwd)
30 | await t.click(this.submitButton)
31 | return t;
32 | }
33 |
This is my first time trying to use test Cafe so I am unclear what is going on.
I suppose that your website doesn't run, and that's why it isn't available at the 3000 port by the "http://localhost:3000/" URL. Could you please check whether you can open the site at "http://localhost:3000/" in your browser before the execution of tests? The web resource tested by TestCafe must be available by the corresponding URL, in your case it is "http://localhost:3000/" .
I'm working with a vue.js project someone else started and I'm putting it on a production server. The npm run build compiles with no errors. But when i try to run the project in the browser i get a
Uncaught SyntaxError: unexpected token <
Here's the index.html
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>tst-apps-suite</title><base href=/ ><link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700,800" rel=stylesheet><link href="https://fonts.googleapis.com/css?family=Dosis:200,400,600,700,800" rel=stylesheet><link href=https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css rel=stylesheet><link href=/static/css/app.d79e04c40fa9145fe427147ef17b4576.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script><script type=text/javascript src=/static/js/vendor.bfe581b46b720086662f.js></script><script type=text/javascript src=/static/js/app.19024fb1db555dd8417b.js></script></body></html>
I get that for all 3 .js asset files.
Server console output on the request. Looks like the files are getting returned:
GET /static/css/app.d79e04c40fa9145fe427147ef17b4576.css 200 1.580 ms - 820
GET /static/js/manifest.2ae2e69a05c33dfc65f8.js 200 3.095 ms - 820
GET /static/js/app.19024fb1db555dd8417b.js 200 3.157 ms - 820
GET /static/js/vendor.bfe581b46b720086662f.js 200 3.429 ms - 820
Any idea how to fix this?
Open the URLs of the scripts each on a different tab (or check the network tab of the developer tools), those URLs are probably returning a 404 (or some other error code) and a HTML error page.
So your code tries to parse those HTML error pages as JavaScript code, thus yielding that error.
It gets Uncaught SyntaxError: Unexpected token < because it tries to parse the HTML content (e.g. <html> ...) as JavaScript code.
Run the snippet below and see the error at the console.
<script type=text/javascript src=https://stackoverflow.com></script>
Check the console: "Uncaught SyntaxError: Unexpected token <"
In my case it was due to the public path in my vue config which was looking for a static path like "/mywidget/" and was looking for assets in "/mywidget/dist/1234.js", which was a problem because in my deployment context there was no "mywidget" folder for the built html to find a js file in.
In my case I set the public path to "/" again and it worked.
I have a simple, bare-bones integration test for a component which depends on an i18n service (which the test injects). The component itself is a simple select dropdown from ember-select-list, with a default value of Select Language. Here's the test:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('language-select', 'Integration | Component | language select', {
integration: true,
beforeEach() {
this.inject.service('i18n');
}
});
test('it renders', function(assert) {
this.render(hbs`{{language-select}}`);
assert.equal(this.$().text().trim().includes('Select Language'), true);
});
When I attempt to just run this one test file (i.e. ember test -f "language-select"), the output I see indicates that only linting tests were performed:
[ hospitalrun-frontend ] $ ember test -f "language-select"
WARNING: Node v7.5.0 is not tested against Ember CLI on your platform. We recommend that you use the most-recent "Active LTS" version of Node.js.
cleaning up...
Built project successfully. Stored in "/Users/richie.thomas/Desktop/Workspace/OpenSource/hospitalrun-frontend/tmp/core_object-tests_dist-5MT1adu7.tmp".
ok 1 PhantomJS 2.1 - ESLint - acceptance/language-select-test.js: should pass ESLint
ok 2 PhantomJS 2.1 - ESLint - components/language-select.js: should pass ESLint
ok 3 PhantomJS 2.1 - TemplateLint - hospitalrun/templates/components/language-select.hbs: should pass TemplateLint
ok 4 PhantomJS 2.1 - ESLint - integration/components/language-select-test.js: should pass ESLint
1..4
# tests 4
# pass 4
# skip 0
# fail 0
# ok
However when I run a plain ember test, I see that this test fails because I am apparently injecting the i18n service incorrectly:
not ok 488 PhantomJS 2.1 - Integration | Component | language select: it renders
---
actual: >
null
expected: >
null
stack: >
http://localhost:7357/assets/hospitalrun.js:4090:18
get#http://localhost:7357/assets/vendor.js:35757:32
get#http://localhost:7357/assets/vendor.js:40664:22
compute#http://localhost:7357/assets/vendor.js:33758:29
value#http://localhost:7357/assets/vendor.js:33625:52
value#http://localhost:7357/assets/vendor.js:65639:37
value#http://localhost:7357/assets/vendor.js:33512:34
create#http://localhost:7357/assets/vendor.js:31495:53
evaluate#http://localhost:7357/assets/vendor.js:66320:43
execute#http://localhost:7357/assets/vendor.js:72898:36
render#http://localhost:7357/assets/vendor.js:72472:30
render#http://localhost:7357/assets/vendor.js:30793:52
runInTransaction#http://localhost:7357/assets/vendor.js:41756:28
_renderRoots#http://localhost:7357/assets/vendor.js:31058:64
_renderRootsTransaction#http://localhost:7357/assets/vendor.js:31096:26
_renderRoot#http://localhost:7357/assets/vendor.js:31017:35
_appendDefinition#http://localhost:7357/assets/vendor.js:30930:23
appendOutletView#http://localhost:7357/assets/vendor.js:30913:29
invoke#http://localhost:7357/assets/vendor.js:19795:19
flush#http://localhost:7357/assets/vendor.js:19865:15
flush#http://localhost:7357/assets/vendor.js:19989:20
end#http://localhost:7357/assets/vendor.js:20059:28
run#http://localhost:7357/assets/vendor.js:20182:19
run#http://localhost:7357/assets/vendor.js:40972:32
render#http://localhost:7357/assets/test-support.js:20665:30
http://localhost:7357/assets/tests.js:15398:16
runTest#http://localhost:7357/assets/test-support.js:3859:34
run#http://localhost:7357/assets/test-support.js:3845:13
http://localhost:7357/assets/test-support.js:4037:15
advance#http://localhost:7357/assets/test-support.js:3522:26
begin#http://localhost:7357/assets/test-support.js:5213:27
http://localhost:7357/assets/test-support.js:4407:11
message: >
Died on test #1 http://localhost:7357/assets/tests.js:15392:24
exports#http://localhost:7357/assets/vendor.js:123:37
requireModule#http://localhost:7357/assets/vendor.js:38:25
require#http://localhost:7357/assets/test-support.js:19547:14
loadModules#http://localhost:7357/assets/test-support.js:19539:21
load#http://localhost:7357/assets/test-support.js:19569:33
http://localhost:7357/assets/test-support.js:7584:22: undefined is not an object (evaluating 'i18n.get')
Log: |
...
I don't see anything in the documentation here about the filter flag affecting the type of tests that are run (i.e. lint vs non-lint tests).
I'm happy to post a separate question about how to properly inject the i18n service, but my question here is:
Why does adding the filter flag result in only filtering tests being run?
It filters module names, not file names. You have dash inside a filter string. Remove it and use space instead:
ember test -f "language select"
I'm trying out MVC 4 Beta's bundling and minification thru System.Web.Optimization. I was hoping that the site I'm using it for would receive a 304 (Not Modified) when I hit refresh.
I thought the point of the src to my js bundle, /desktop-js-bundle?v=D33JhbMl9LHkXSPBj1tfRkRI0lHeYVmbSMQqD59bXHg1 (with that version #), was that the version # changed only when one of the files in the bundle on the server was modified. Yet, every time I hit refresh and monitor the Network tab in Chrome's F12, it makes a request with that same version number and gets a 200 status.
Why doesn't it just return 304?, which would decrease the load and increase perf a decent amount. Thanks!
Why doesn't it just return 304?
Because when you hit F5 you expire the cache of your browser. Basically your test is flawed. You should put links to this bundle in different pages (using the <script> tag). Then you should navigate to those pages using hyperlinks. Now observe the Network tab.
Also make sure you are running in Release mode.
UPDATE:
OK, after digging a little more here's what I found out. The 200 HTTP status code is indeed always sent which is normal. But the second time the bundle is fetched from the cache.
Here's the first request:
We can see that in this case the bundle comes from the server with HTTP cache response headers.
And here's the second request:
We can clearly see in this second screenshot that the bundle is served from the cache. Notice how the entire line is grayed. The HTTP 200 status code is fictional => the client doesn't even send an HTTP request to the server as it retrieves the bundle directly from its cache.
And I can observe the same thing in Google Chrome.
For the first request:
And for the second request:
I had the same issue and the problem was with Microsoft.AspNet.Web.Optimization package. As described here: http://aspnetoptimization.codeplex.com/workitem/127, versions 1.1.2 - 1.1.3 are affected. After downgrade to 1.1.1 it works fine and 304 is returned for non-changed resources after refresh.
You can do it in Package Manager Console with following commands:
PM> Uninstall-Package "Microsoft.AspNet.Web.Optimization"
PM> Install-Package "Microsoft.AspNet.Web.Optimization" -Version 1.1.1