webship-js 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,13 +18,7 @@ All you need to know is at [webship-js Docs](https://webship.co/docs/webship-js/
18
18
  npm install webship-js
19
19
  ```
20
20
 
21
- ## Install files required by the webship-js tool
22
-
23
- ```
24
- bash <(wget -O - https://raw.githubusercontent.com/webship/wbash/v1/webship-js/v2/template.sh)
25
- ```
26
-
27
- ## Automated Functional Acceptance Testing
21
+ ## Automated Functional Acceptance Testing
28
22
 
29
23
  ```
30
24
  npm test
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { spawnSync } = require('child_process');
8
+
9
+ // The directory where `npm install` was invoked (the user's project root)
10
+ const projectPath = process.env.INIT_CWD || process.cwd();
11
+
12
+ // The webship-js package directory
13
+ const packagePath = path.join(__dirname, '..');
14
+
15
+ // Skip if running inside webship-js itself (e.g. during development or CI of webship-js)
16
+ if (
17
+ projectPath === packagePath ||
18
+ projectPath.startsWith(path.join(packagePath, 'node_modules'))
19
+ ) {
20
+ process.exit(0);
21
+ }
22
+
23
+ // Path to required template files bundled with webship-js
24
+ const requiredDir = path.join(packagePath, 'required');
25
+
26
+ function copyDirSync(src, dest) {
27
+ fs.mkdirSync(dest, { recursive: true });
28
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
29
+ const srcPath = path.join(src, entry.name);
30
+ const destPath = path.join(dest, entry.name);
31
+ if (entry.isDirectory()) {
32
+ copyDirSync(srcPath, destPath);
33
+ } else {
34
+ fs.copyFileSync(srcPath, destPath);
35
+ }
36
+ }
37
+ }
38
+
39
+ // Only copy template files on a fresh install (tests/ not yet present)
40
+ const testsTarget = path.join(projectPath, 'tests');
41
+ if (!fs.existsSync(testsTarget)) {
42
+ console.log('\n [webship-js] Installing required files...\n');
43
+
44
+ copyDirSync(path.join(requiredDir, 'tests'), testsTarget);
45
+
46
+ fs.copyFileSync(
47
+ path.join(requiredDir, 'generate-reports.js'),
48
+ path.join(projectPath, 'generate-reports.js')
49
+ );
50
+
51
+ fs.copyFileSync(
52
+ path.join(requiredDir, 'cucumber.js'),
53
+ path.join(projectPath, 'cucumber.js')
54
+ );
55
+
56
+ fs.copyFileSync(
57
+ path.join(requiredDir, 'tsconfig.json'),
58
+ path.join(projectPath, 'tsconfig.json')
59
+ );
60
+
61
+ fs.copyFileSync(
62
+ path.join(requiredDir, 'playwright.config.ts'),
63
+ path.join(projectPath, 'playwright.config.ts')
64
+ );
65
+
66
+ // Only copy package.json if the project does not have one yet
67
+ const targetPkgJson = path.join(projectPath, 'package.json');
68
+ if (!fs.existsSync(targetPkgJson)) {
69
+ fs.copyFileSync(path.join(requiredDir, 'package.json'), targetPkgJson);
70
+ }
71
+ }
72
+
73
+ // Always ensure the test scripts are present in package.json
74
+ const targetPkgJson = path.join(projectPath, 'package.json');
75
+ if (fs.existsSync(targetPkgJson)) {
76
+ const pkgJson = JSON.parse(fs.readFileSync(targetPkgJson, 'utf8'));
77
+ pkgJson.scripts = pkgJson.scripts || {};
78
+ pkgJson.scripts.test = 'cucumber-js --config cucumber.js; node generate-reports.js;';
79
+ pkgJson.scripts['test:firefox'] = 'BROWSER=firefox cucumber-js --config cucumber.js; node generate-reports.js;';
80
+ pkgJson.scripts['test:webkit'] = 'BROWSER=webkit cucumber-js --config cucumber.js; node generate-reports.js;';
81
+ fs.writeFileSync(targetPkgJson, JSON.stringify(pkgJson, null, 2) + '\n', 'utf8');
82
+ }
83
+
84
+ // Install Playwright browsers
85
+ console.log('\n [webship-js] Installing Playwright browsers...\n');
86
+ spawnSync('npx', ['playwright', 'install', '--with-deps', 'chromium'], {
87
+ cwd: projectPath,
88
+ stdio: 'inherit',
89
+ shell: true,
90
+ });
91
+
92
+ console.log('\n [webship-js] Setup complete!\n');
@@ -0,0 +1,32 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>My Account</title>
6
+ <style>
7
+ body { font-family: sans-serif; max-width: 600px; margin: 60px auto; padding: 0 20px; }
8
+ h1 { color: #333; }
9
+ .account-info { background: #f5f5f5; border-radius: 6px; padding: 20px; margin-top: 20px; }
10
+ a { color: #0066cc; }
11
+ </style>
12
+ <script>
13
+ function getCookie(name) {
14
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
15
+ return match ? decodeURIComponent(match[1]) : null;
16
+ }
17
+
18
+ window.addEventListener('DOMContentLoaded', function () {
19
+ if (!getCookie('session')) {
20
+ window.location.replace('/');
21
+ }
22
+ });
23
+ </script>
24
+ </head>
25
+ <body>
26
+ <h1>My Account</h1>
27
+ <div class="account-info">
28
+ <p>Welcome back! You are logged in.</p>
29
+ <p><a href="/">Back to homepage</a></p>
30
+ </div>
31
+ </body>
32
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -10,6 +10,7 @@
10
10
  "node": ">= 20.0"
11
11
  },
12
12
  "scripts": {
13
+ "postinstall": "node ./bin/postinstall.js",
13
14
  "test": "cucumber-js --config cucumber.js; node generate-reports.js;",
14
15
  "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js; node generate-reports.js;",
15
16
  "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js; node generate-reports.js;",
@@ -0,0 +1,37 @@
1
+ module.exports = {
2
+ default: {
3
+ timeout: 30000,
4
+ requireModule: ['ts-node/register'],
5
+ require: [
6
+ 'node_modules/webship-js/tests/step-definitions/**/*.js',
7
+ 'tests/step-definitions/**/*.js',
8
+ ],
9
+ paths: ['tests/features/**/*.feature'],
10
+ format: [
11
+ '@cucumber/pretty-formatter',
12
+ 'json:tests/reports/cucumber_report.json',
13
+ ],
14
+ formatOptions: {
15
+ colorsEnabled: true,
16
+ theme: {
17
+ 'feature keyword': ['bold', 'blue'],
18
+ 'feature name': ['blue', 'underline'],
19
+ 'feature description': ['blueBright'],
20
+ 'scenario keyword': ['bold', 'magenta'],
21
+ 'scenario name': ['magenta', 'underline'],
22
+ 'step keyword': ['bold', 'green'],
23
+ 'step text': ['greenBright', 'italic'],
24
+ },
25
+ },
26
+ worldParameters: {
27
+ launchUrl: process.env.LAUNCH_URL || 'http://localhost:8080',
28
+ minWaitTime: {
29
+ page: 3000,
30
+ before_scenario: 0,
31
+ after_scenario: 0,
32
+ before_step: 0,
33
+ after_step: 0,
34
+ },
35
+ },
36
+ },
37
+ };
@@ -0,0 +1,22 @@
1
+ var reporter = require('cucumber-html-reporter');
2
+
3
+ var options = {
4
+ theme: 'bootstrap',
5
+ jsonFile: 'tests/reports/cucumber_report.json',
6
+ output: 'tests/reports/cucumber_report.html',
7
+ reportSuiteAsScenarios: true,
8
+ scenarioTimestamp: true,
9
+ launchReport: false,
10
+ brandTitle: "Test Report",
11
+ metadata: {
12
+ "App Version": "7.1.0",
13
+ "Test Environment": "development",
14
+ "Browser": "Google Chrome",
15
+ "Platform": "Linux",
16
+ "Parallel": "Scenarios",
17
+ "Executed": "Remote"
18
+ },
19
+ failedSummaryReport: true,
20
+ };
21
+
22
+ reporter.generate(options);
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "project-name",
3
+ "version": "2.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "scripts": {
10
+ "test": "cucumber-js --config cucumber.js; node generate-reports.js;",
11
+ "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js; node generate-reports.js;",
12
+ "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js; node generate-reports.js;"
13
+ },
14
+ "homepage": "https://github.com/webship/webship-js",
15
+ "dependencies": {
16
+ "webship-js": "~2.0.0"
17
+ }
18
+ }
@@ -0,0 +1,37 @@
1
+ import type { LaunchOptions, BrowserContextOptions } from 'playwright';
2
+
3
+ type BrowserName = 'chromium' | 'firefox' | 'webkit';
4
+
5
+ const browser = (process.env.BROWSER || 'chromium') as BrowserName;
6
+
7
+ const chromiumArgs: string[] = [
8
+ '--no-sandbox',
9
+ '--disable-dev-shm-usage',
10
+ '--disable-setuid-sandbox',
11
+ '--disable-web-security',
12
+ '--ignore-certificate-errors',
13
+ '--disable-extensions',
14
+ '--incognito',
15
+ '--disable-infobars',
16
+ ];
17
+
18
+ interface PlaywrightConfig {
19
+ browser: BrowserName;
20
+ launchOptions: LaunchOptions;
21
+ contextOptions: BrowserContextOptions;
22
+ }
23
+
24
+ const config: PlaywrightConfig = {
25
+ browser,
26
+ launchOptions: {
27
+ headless: true,
28
+ slowMo: 300,
29
+ args: browser === 'chromium' ? chromiumArgs : [],
30
+ },
31
+ contextOptions: {
32
+ viewport: { width: 1600, height: 1200 },
33
+ ignoreHTTPSErrors: true,
34
+ },
35
+ };
36
+
37
+ export = config;
@@ -0,0 +1 @@
1
+ # Features
@@ -0,0 +1,8 @@
1
+ Feature: Check the home page
2
+ As a nonymouse user
3
+ I want to be able to visit the home page
4
+ So that I know that the site is working
5
+
6
+ Scenario: Check homepage
7
+ Given I am on the homepage
8
+ Then I should see "Love to help in speeding up the work of having Automated Functional Acceptance Testing for products to ship websites in a swift way."
@@ -0,0 +1 @@
1
+ # Reports
@@ -0,0 +1 @@
1
+ # Step Definitions
@@ -0,0 +1,4 @@
1
+ const { Given, When, Then } = require('@cucumber/cucumber');
2
+ const playwrightConfig = require(require('path').join(process.cwd(), 'playwright.config'));
3
+
4
+ // Add your custom step definitions here.
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "types": ["node"]
8
+ },
9
+ "ts-node": {
10
+ "ignore": ["node_modules/(?!webship-js/)"]
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ Feature: Given I am an anonymous user
2
+
3
+ Scenario: Anonymous user is redirected to homepage with no cookies
4
+ Given I am an anonymous user
5
+ Then the url should match "\/"
6
+
7
+ Scenario: Anonymous user cannot access a protected page
8
+ Given I am an anonymous user
9
+ When I go to "/account"
10
+ Then I should not be on the "/account" page
@@ -189,6 +189,16 @@ async function isAnyModalVisible(page) {
189
189
  );
190
190
  }
191
191
 
192
+ // ---------------------------------------------------------------------------
193
+ // Given I am an anonymous user
194
+ // Captures: (pronounCase) = 1
195
+ // ---------------------------------------------------------------------------
196
+ Given(/^(I am |we are )?an anonymous user$/, async function (pronounCase) {
197
+ await this.context.clearCookies();
198
+ await gotoUrl(this.page, this.launchUrl);
199
+ await waitForPageLoad(this.page, this.minWaitTime.page || 3000);
200
+ });
201
+
192
202
  // ---------------------------------------------------------------------------
193
203
  // Given I am on homepage / frontpage
194
204
  // Captures: (pronounCase, theCase, pageCase) = 3