question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues running cookie test code

See original GitHub issue

I can’t seem to run the cookie test code.

Here’s my package.json

  "name": "realtimechat",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "dropzone": "^5.9.2",
    "jest": "^27.0.3",
    "server": "^1.0.33"
  },
  "devDependencies": {
    "css-loader": "^5.2.6",
    "style-loader": "^2.0.0",
    "webpack-cli": "^4.7.0"
  },
  "scripts": {
    "start": "node index.js",
    "test": "jest --coverage --forceExit"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/dpaschal7/RealTimeChat.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/dpaschal7/RealTimeChat/issues"
  },
  "homepage": "https://github.com/dpaschal7/RealTimeChat#readme"
}

I keep getting a ReferenceError for run what other dependencies are missing

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
franciscopcommented, Jun 2, 2021

Thanks for opening an issue, certainly testing is well under-documented so I’ll try to explain the basics in this issue. I would not recommend using run at all for your own tests; it’s here for internal tests and definitely nowhere near stable. Instead, use some 3rd party testing library like supertest:

// index.js - Main project file
const server = require('server');
const { get } = server.router;

// Notice that we export the server here for testing later on:
module.exports = server(
  get('/user', () => ({ name: 'john' }))
);

Your test file (need to npm install supertest jest --save-dev first):

// index.test.js - API testing file
const request = require('supertest');

// The promise exported from your index
const serverPromise = require('./index.js');

// This will be populated after the server has launched. You can call it
// anything you want; server, runtime, ctx, instance, etc. are all valid names
let server;

describe('user', () => {
  // Populate it with the running instance when it's ready
  beforeAll(async () => {
    server = await serverPromise;
  });
  // Avoid leaving it hanging after all the tests have run
  afterAll(async () => {
    await server.close();
  });
  it('tests the user endpoint', async () => {
    await request(server.app)
      .get('/user')
      .expect('Content-Type', /json/)
      .expect('Content-Length', '15')
      .expect(200);
  });
});

Things become more difficult if you want to require() it from different files because then it’s launched multiple times with the same port (so it’ll fail). I recommend a single entry point like the above for testing for the API itself.

0reactions
franciscopcommented, Jun 16, 2021

This seems to be fixed, or at least it’s been answered. Please feel free to reopen if you still have an issue here or to create a new issue asking more questions. Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Website Cookie Testing & Test Cases for Testing Web ...
This article will explain to you all about HTTP or Internet cookie testing in detail. with test cases for Web Application Cookie Testing....
Read more >
Cookie Testing: How to Test Cookies in Website with Example
1. Disable all cookies and attempt to use the site’s major functions 2. Manually edit the cookie in notepad and change the parameters...
Read more >
Cookie Testing: Example Test Cases for Website - Tutorialspoint
A test that is specific Check if the same Cookies are allowed in all environments for multi-environment sites. The usage of wildcards in...
Read more >
Cookie Testing: The Critical Part of Website Tests - TestOrigen
It is one of the simplest methods for executing the website cookie testing. This technique assesses the working of major functional regions of ......
Read more >
Persisting session cookies is not working · Issue #336 - GitHub
I am having an issue persisting the correct cookies when trying to test an endpoint that ... The second test runs as expected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found