Git Product home page Git Product logo

mocha-examples's People

Contributors

angie4u avatar bseib avatar craigtaub avatar dependabot[bot] avatar hyunsanghan avatar irrationnelle avatar jerell-mendoza avatar juergba avatar moonsupport avatar outsideris avatar pukuba avatar seohyun0120 avatar tim-we avatar vit100 avatar vkarpov15 avatar wnghdcjfe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mocha-examples's Issues

Example needed for cli testing tool

I have a file fele.js that specifies all commands that my app needs.

Command Used - Just says hello world when hello is entered.

const program = new commander.Command();
const helloCommand = program.command('hello');
helloCommand
    .action(async(options) => {
       console.log("Hello World"); //Works well as 
        return "Hello World";//But this does not work. 
    })

Now I am using Mocha to test the command. PFB Code

const assert = require('assert');
const { spawn } = require('child_process');
const path = require('path');

describe('Hello Command', function() {
  it('should output a greeting message', function(done) {
    const expectedOutput = 'Hello World\n';
    const cliPath = path.join(__dirname,'fele.js'); 
    const process = spawn('node', [cliPath, 'hello']);
    let actual = '';
    process.stdout.on('data', data => {
      actual += data.toString();
    });
    process.on('close', () => {
      assert.strictEqual(output, expectedOutput);
      done();
    });
  });
});```

Please do suggest me an approach with which I can be able to get not only by using console.log but also by using return statement. Like process.stdout.on works for console.log statements, suggest me some thing that works for a process's method return value.

selenium test is not working in latest chrome

selenium test is not working in latest chrome

npm install and npm test
my OS : macOS
my Chrome : 77(latest)

  1. npm install
  2. npm test
  3. and then occured this message
SessionNotCreatedError: session not created: Chrome version must be between 71 and 75
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.6 x86_64)

So I edited little of code and Test it

The result

Testing without mocha

const { Builder, By, Key, Capabilities } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const path = require("chromedriver").path;

const chromeOptions = new chrome.Options().headless();
(async function example() {
  var driver = await new Builder(path)
    .forBrowser("chrome")
    .setChromeOptions(chromeOptions)
    .build();

  try {
    await driver.get("http://www.google.com/ncr");
    await driver.findElement(By.name("q")).sendKeys("webdriver", Key.RETURN);
    const ret = await driver.findElement(By.css(".LC20lb")).getText();
    console.log(ret);
  } finally {
    await driver.quit();
  }
})();

It is worked

Testing with mocha

edited selenium.spec.js

import "@babel/polyfill";
import chrome from "selenium-webdriver/chrome";
import { Builder, By, Key, Capabilities } from "selenium-webdriver";
import assert from "assert";
import { path } from "chromedriver";
let driver = null;
const chromeOptions = new chrome.Options().headless();

describe("Selenium", () => {
  beforeEach(async () => {
    driver = await new Builder(path)
      .forBrowser("chrome")
      .setChromeOptions(chromeOptions)
      .build();

    await driver.get("http://www.google.com/");
  });

  afterEach(async () => {
    await driver.quit();
  });

  it('should render "Selenium WebDriver" on a Google search result', async () => {
    const element = await driver.findElement(By.name("q"));
    await element.sendKeys("webdriver", Key.RETURN);
    const res = await driver.findElement(By.css(".LC20lb")).getText();

    assert.equal(res, "Selenium WebDriver");
  });
});

I added package.json npm install --save-dev chromedriver and edit like this. But It is not worked occuring same reason.

copyright notices

We're going to need an appropriate copyright notice for the Foundation in the README.md, and an updated LICENSE file (at minimum).

We will want to hold off on this until we're given the green light to change over the main repo.

TypeError: Unknown file extension ".ts" |

package.json

  "name": "sd-tracker-api",
  "version": "1.0.0",
  "description": "",
  "main": "main.ts",
  "scripts": {
    "build": "tsc -p .",
    "dev": "SET NODE_ENV=dev & ts-node-dev --respawn --transpile-only -r tsconfig-paths/register src/main.ts",
    "test": "SET NODE_ENV=test & mocha --check-leaks -r ts-node/register -r tsconfig-paths/register tests/**.spec.ts"
  },
  "author": "Jason Terry",
  "license": "ISC",
  "devDependencies": {
    "@types/chai": "^4.3.11",
    "@types/express": "^4.17.21",
    "@types/mocha": "^10.0.6",
    "@types/node": "^20.10.6",
    "@types/supertest": "^6.0.2",
    "chai": "^5.0.0",
    "mocha": "^10.2.0",
    "supertest": "^6.3.3",
    "ts-node": "^10.9.2",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.3.3"
  },
  "dependencies": {
    "dotenv": "^16.3.1",
    "express": "^4.18.2"
  }
}

tsconfig.json

{
  "exclude": ["./coverage", "./dist", "./node_modules"],
  "ts-node": {
    "transpileOnly": true,
    "files": true
  },
  "compilerOptions": {
    "target": "es2016", 
    "module": "Node16",  
    "rootDir": "./src",    
    "moduleResolution": "Node16",
    "baseUrl": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,                             
    "forceConsistentCasingInFileNames": true,            
    "strict": true,                                      
    "skipLibCheck": true                                 
  }
}

.mocharc.json

{
  "extension": ["ts"],
  "spec": "tests/**/*.spec.ts",
  "require": "ts-node/register"
}

Greetings, I am unable to run mocha when including import { expect } from 'chai'; into my project.

It causes the following to occour.

npm run test

> [email protected] test
> SET NODE_ENV=test & mocha --check-leaks -r ts-node/register -r tsconfig-paths/register tests/**.spec.ts


TypeError: Unknown file extension ".ts" for E:\my-learning\sd-tracker-api\tests\types.spec.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:141:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21)

I am not sure what to do to solve this? I followed the guidance of the following video along with the TS example project.

Video
Project

Any help would be greatly appreciated.

Documentation for usage with Karma/Angular 4+

I assume that since older versions of mocha worked with older versions of Angular, that this is still possible, but all of the references I can find online for this are varied and not helpful. I think it would be helpful for this project if there was an official documentation for how to set up mocha for Karma and Angular.

How to pass variables from a --file setup to all the tests?

In this example there is a before and after hooks in a separated file using the Mocha --file command.
How can I create variables inside those hooks and to be accessible in other tests? For example:

prepare.js

before(function() {
    this.myVariable = 123;
});

myTest.spec.js

describe('Just a simple test', function () {
  it('Verifies the myVariable variable', async () => {
    expect(this.myVariable).to.eq(123); //should pass
  });
});

CLABot

agh, we need to set up the CLA bot here.

Improving test isolation in Workflow

Summary:

The current workflow runs all tests together in a single job, causing two main issues:

  1. Tracking Difficulty:

    • It's challenging to distinguish which examples are functioning correctly and which aren't.
  2. Dependency Interference:

    • Shared system dependencies might lead to misleading test results; an example might pass due to a dependency installed by a different example.

Proposed Solutions:

  1. Matrix Strategy:

    • Consider replacing Lerna with a matrix strategy in the workflow, iterating over each package's folder independently.
    strategy:
      matrix:
        folder:
          - example1
          - example2
          - example3
        node-version:
          - 16
          - 18
  2. Separate Repositories:

    • Alternatively, use individual repositories for each example, each with its own workflows. Add them as submodules to a main repository.

Typescript root level hooks

Could you provide an example of root level hooks like described here for typescript? When I create a hooks.js or hooks.ts it doesn't get called.

Add more examples for Express.js

Add more examples for the express-rest-api package, preferably handling more methods such as POST and covering more scenarios for testing (missing fields in req body, headers etc).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.