Giter Site home page Giter Site logo

cordejs / corde Goto Github PK

View Code? Open in Web Editor NEW
117.0 2.0 9.0 37.52 MB

๐Ÿค– A simple e2e library for testing Discord Bots ๐Ÿš€

Home Page: https://cordejs.org

License: MIT License

JavaScript 3.04% TypeScript 77.21% Shell 0.24% CSS 0.37% Batchfile 0.01% C# 0.14% Markdown 18.98%
discord-bot corde automated-testing e2e nodejs discordbot discordjs

corde's Introduction

๐Ÿ˜€ Table of Content

๐Ÿ‘€ About

Corde is a small testing library for Discord.js. As there is a tool to create bots for Discord, it's cool to also have a tool to test them. Corde objective is to be simple, fast, and readable to developers.

Documentation

The bellow documentation is a resume of what you can find in Corde's site

๐Ÿš€ Getting started

Node.js 14.0 or newer is required

Starting to create tests with Corde is simple. First, install it locally with npm npm i -D corde or yarn yarn add -D corde.

After installed, add the file corde.config.json in the root of your application with the following structure:

{
   "cordeBotToken":  "<tokenForCordeBot>",
   "botTestId":  "<yourBotId>",
   "guildId":  "<guildId>",
   "channelId":  "<channelId>",
   "botPrefix":  "!",
   "testMatches":  ["./test/**"]
}

Test example:

const { group, test, command, beforeStart, afterAll } = require("corde");
const { client, loginBot } = require("..");

beforeStart(async () => {
  await loginBot();
});

group("main commands", () => {
  test("ping command must return... Ping?!!", () => {
    expect("ping").toReturn("Ping?");
  });
});

afterAll(() => {
  client.destroy();
});

corde's People

Contributors

averagehelper avatar code-factor avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar imgbotapp avatar lucasgmagalhaes avatar randergabriel 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

corde's Issues

create toDeleteMessage command.

With this command, user can delete the last message sent by the bot(default) but can also delete the message by id or by order.
It also has some options

interface DeleteOption {
  /**
   * How many messages to delete
   */
  amount?: number;
  /**
   * Defines its positions.
   * @example
   *
   * // Supose that we have these messages:
   *
   *  "Hi",
   *  "Hello",
   *  "Good morning"
   * 
   * // If is passaed 0, 2
   * // Messages "Good morning" and "Hi" will be deleted
   */
  positions?: number | number[];
  /**
   * Deletes messages by its content
   */
  content?: string | string[];
}

export function mustDeleteMessage(...content: string[]): void;
export function mustDeleteMessage(content: string | string[] | number | DeleteOption): void;

I.E:

command("delete").mustDeleteMessage() // Deletes last bot message sent
command("delete").mustDeleteMessage(1) // Deletes last bot message sent also
command("delete").mustDeleteMessage(2) // Deletes last 2 bot messages sent
command("delete").mustDeleteMessage({ amount: 10}) // Deletes last 10 bot messages sent
command("delete").mustDeleteMessage({ positions: [0, 2]}) // Deletes last and thirt message sent
command("delete").mustDeleteMessage({ content: ["Hi", "Hello" ]}) // Deletes Messages Hi and Hello

rewrite architeture

It's totally confuse and complex to add new features. The project structure must be rewrite

create init command

This command allow user to create a config file with default values and with the desired extension
js, ts or json

Create afterEach function

/**
 * Declare a bunch of code that will be executed **after each** test.
 *
 * More than one declaration of this code results in a list
 * of functions to run, following a sequence of files
 * reads and the positions of each `afterEach` call.
 *
 * @param fn code that will be executed **after each** tests finish
 */
export function afterEach(fn: () => void)

Your .dependabot/config.yml contained invalid details

Dependabot encountered the following error when parsing your .dependabot/config.yml:

The property '#/update_configs/1/package_manager' value "daily" did not match one of the following values: javascript, ruby:bundler, php:composer, java:maven, elixir:hex, rust:cargo, java:gradle, dotnet:nuget, go:dep, go:modules, docker, elm, submodules, github_actions, python, terraform

Please update the config file to conform with Dependabot's specification using our docs and online validator.

Treat discord logout if error

When a internal error appear in tests executions while bots are loged. this happens i.e:

Client bot is ready for tests!
TypeError: test is not a function
    at Object.<anonymous> (E:\Git\concord\tests\simple-messages\testWait1.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at E:\Git\concord\lib\shell.js:12:13
    at Array.forEach (<anonymous>)
    at Object.runTest (E:\Git\concord\lib\shell.js:10:13)
(node:2444) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
  target: WebSocket {
    _events: [Object: null prototype] {
      message: [Function],
      open: [Function],
      error: [Function],
      close: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    readyState: 2,
    protocol: '',
    _binaryType: 'nodebuffer',
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _closeCode: 1006,
    _extensions: {},
    _receiver: null,
    _sender: null,
    _socket: null,
    _isServer: false,
    _redirects: 0,
    url: 'wss://gateway.discord.gg/?v=6&encoding=json',
    _req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'GET /?v=6&encoding=json HTTP/1.1\r\n' +
        'Sec-WebSocket-Version: 13\r\n' +
        'Sec-WebSocket-Key: sLuzCsPoJKiWzJ+iZ5irTQ==\r\n' +
        'Connection: Upgrade\r\n' +
        'Upgrade: websocket\r\n' +
        'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n' +
        'Host: gateway.discord.gg\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: undefined,
      socketPath: undefined,
      method: 'GET',
      path: '/?v=6&encoding=json',
      _ended: false,
      res: null,
      aborted: true,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: [HTTPParser],
      maxHeadersCount: null,
      [Symbol(isCorked)]: false,
      [Symbol(outHeadersKey)]: [Object: null prototype]
    }
  },
  type: 'error',
  message: 'WebSocket was closed before the connection was established',
  error: Error: WebSocket was closed before the connection was established
      at WebSocket.close (E:\Git\concord\node_modules\ws\lib\websocket.js:217:14)
      at WebSocketConnection.destroy (E:\Git\concord\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:276:8)
      at WebSocketManager.destroy (E:\Git\concord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:52:28)
      at ClientManager.destroy (E:\Git\concord\node_modules\discord.js\src\client\ClientManager.js:60:20)
      at Client.destroy (E:\Git\concord\node_modules\discord.js\src\client\Client.js:292:25)
      at Object.<anonymous> (E:\Git\concord\lib\bot.js:92:33)
      at Generator.next (<anonymous>)
      at fulfilled (E:\Git\concord\lib\bot.js:4:58)
      at processTicksAndRejections (internal/process/task_queues.js:85:5)
})
    at Client.emit (events.js:192:17)
    at WebSocketConnection.onError (E:\Git\concord\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:374:17)
    at WebSocket.onError (E:\Git\concord\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:203:13)
    at abortHandshake (E:\Git\concord\node_modules\ws\lib\websocket.js:718:15)
    at WebSocket.close (E:\Git\concord\node_modules\ws\lib\websocket.js:217:14)
    at WebSocketConnection.destroy (E:\Git\concord\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:276:8)
    at WebSocketManager.destroy (E:\Git\concord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:52:28)
    at ClientManager.destroy (E:\Git\concord\node_modules\discord.js\src\client\ClientManager.js:60:20)
    at Client.destroy (E:\Git\concord\node_modules\discord.js\src\client\Client.js:292:25) {
  context: ErrorEvent {
    target: WebSocket {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      readyState: 3,
      protocol: '',
      _binaryType: 'nodebuffer',
      _closeFrameReceived: false,
      _closeFrameSent: false,
      _closeMessage: '',
      _closeTimer: null,
      _closeCode: 1006,
      _extensions: {},
      _receiver: null,
      _sender: null,
      _socket: null,
      _isServer: false,
      _redirects: 0,
      url: 'wss://gateway.discord.gg/?v=6&encoding=json',
      _req: [ClientRequest]








        at processTicksAndRejections (internal/process/task_queues.js:85:5)
  }
}

create toReply command.

Reply a message using the corde bot name

Structure:

export function mustReply(message: number | string)

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.