Skip to content

Commit 2fe8393

Browse files
feat: add playwright exmaple (#37)
* 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
1 parent b752e0c commit 2fe8393

File tree

12 files changed

+1469
-123
lines changed

12 files changed

+1469
-123
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A set of examples to help demontrate common configurations using Mocha. They sho
2020
- [TypeScript, Babel](packages/typescript-babel/)
2121
- [Express REST API](packages/express-rest-api/)
2222
- [Node Sqlite 3 example](packages/node-sqlite3/)
23+
- [Playwright application](packages/playwright/)
2324

2425
## Adding a new example
2526

packages/node-sqlite3/src/index.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,39 @@ exports.initDB = function initDB(path) {
55
};
66

77
exports.createTable = function createTable(db) {
8-
return db.run(
9-
"CREATE TABLE IF NOT EXISTS user(id integer primary key, name text not null, email text unique)"
10-
);
8+
return new Promise((resolve, reject)=> {
9+
db.run("CREATE TABLE IF NOT EXISTS user(id integer primary key, name text not null, email text unique)", (err)=>{
10+
if(err) {
11+
reject(err);
12+
} else {
13+
resolve()
14+
}
15+
});
16+
})
1117
};
1218

1319
exports.dropTable = function dropTable(db) {
14-
return db.run("DROP TABLE IF EXISTS user");
20+
return new Promise((resolve, reject) => {
21+
db.run("DROP TABLE IF EXISTS user", (err)=> {
22+
if(err) {
23+
reject(err);
24+
} else {
25+
resolve();
26+
}
27+
});
28+
})
1529
};
1630

1731
exports.insertUser = function insertUser(db, name, email) {
18-
return db.run(`INSERT INTO user(name, email) VALUES('${name}', '${email}')`);
32+
return new Promise((resolve, reject) => {
33+
db.run(`INSERT INTO user(name, email) VALUES('${name}', '${email}')`, (err)=> {
34+
if(err) {
35+
reject(err);
36+
} else {
37+
resolve();
38+
}
39+
});
40+
})
1941
};
2042

2143
exports.getUsersByName = function getUsersByName(db, name) {

packages/node-sqlite3/test/index.spec.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ const {
1010

1111
describe("Sqlite", function () {
1212
let db;
13-
before(() => {
13+
before((done) => {
1414
db = initDB(':memory:');
15-
db.serialize(function() {
16-
dropTable(db);
17-
createTable(db);
15+
db.serialize(async function() {
16+
await dropTable(db);
17+
await createTable(db);
18+
done();
1819
});
1920
});
2021

2122
it("should insert and fetch a user", async () => {
2223
const name = "mocha";
2324
const email = "[email protected]";
2425

25-
insertUser(db, name, email);
26+
await insertUser(db, name, email);
2627
const user = await getUsersByName(db, name);
2728
assert.deepEqual(user, [{ id: 1, name, email }]);
2829
});

packages/playwright/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

packages/playwright/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Playwright
2+
3+
Basic example for mocha and playwright(`^1.3.0`)
4+
5+
## Commands
6+
7+
- `npm test` - Run mocha test. Visit [Mocha Page](https://mochajs.org) and assert actual text on Chromium.

0 commit comments

Comments
 (0)