Skip to content

Commit

Permalink
feat: add playwright exmaple (#37)
Browse files Browse the repository at this point in the history
* feat: add playwright exmaple

* fix: set headless mode to pass test on travis CI/CD

* chore: add link to playwright example on README.md

* fix: remove unnecessary options that have already default values in mocharc.json

* fix: replace assert.equal() with assert.strictEqual()

- assert.equal() is deprecated since node v10

* fix: modify timeout properly

* fix: update chromedrive version to pass Travis CI

* fix: update package-lock.json for chromedriver latest

* fix: add await and done keyword to complete explicitly async operation

* fix: modify timeout for selenium and vue-puppeteer to pass Travis CI

* fix: apply promise for async operation

* fix: modify timeout value to pass Travis CI

* fix: modify timeout properly
  • Loading branch information
irrationnelle committed Sep 3, 2020
1 parent b752e0c commit 2fe8393
Show file tree
Hide file tree
Showing 12 changed files with 1,469 additions and 123 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A set of examples to help demontrate common configurations using Mocha. They sho
- [TypeScript, Babel](packages/typescript-babel/)
- [Express REST API](packages/express-rest-api/)
- [Node Sqlite 3 example](packages/node-sqlite3/)
- [Playwright application](packages/playwright/)

## Adding a new example

Expand Down
32 changes: 27 additions & 5 deletions packages/node-sqlite3/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,39 @@ exports.initDB = function initDB(path) {
};

exports.createTable = function createTable(db) {
return db.run(
"CREATE TABLE IF NOT EXISTS user(id integer primary key, name text not null, email text unique)"
);
return new Promise((resolve, reject)=> {
db.run("CREATE TABLE IF NOT EXISTS user(id integer primary key, name text not null, email text unique)", (err)=>{
if(err) {
reject(err);
} else {
resolve()
}
});
})
};

exports.dropTable = function dropTable(db) {
return db.run("DROP TABLE IF EXISTS user");
return new Promise((resolve, reject) => {
db.run("DROP TABLE IF EXISTS user", (err)=> {
if(err) {
reject(err);
} else {
resolve();
}
});
})
};

exports.insertUser = function insertUser(db, name, email) {
return db.run(`INSERT INTO user(name, email) VALUES('${name}', '${email}')`);
return new Promise((resolve, reject) => {
db.run(`INSERT INTO user(name, email) VALUES('${name}', '${email}')`, (err)=> {
if(err) {
reject(err);
} else {
resolve();
}
});
})
};

exports.getUsersByName = function getUsersByName(db, name) {
Expand Down
11 changes: 6 additions & 5 deletions packages/node-sqlite3/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ const {

describe("Sqlite", function () {
let db;
before(() => {
before((done) => {
db = initDB(':memory:');
db.serialize(function() {
dropTable(db);
createTable(db);
db.serialize(async function() {
await dropTable(db);
await createTable(db);
done();
});
});

it("should insert and fetch a user", async () => {
const name = "mocha";
const email = "mocha@test.com";

insertUser(db, name, email);
await insertUser(db, name, email);
const user = await getUsersByName(db, name);
assert.deepEqual(user, [{ id: 1, name, email }]);
});
Expand Down
1 change: 1 addition & 0 deletions packages/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions packages/playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Playwright

Basic example for mocha and playwright(`^1.3.0`)

## Commands

- `npm test` - Run mocha test. Visit [Mocha Page](https://mochajs.org) and assert actual text on Chromium.
Loading

0 comments on commit 2fe8393

Please sign in to comment.