@bucky24/jsbehave 0.11.0 → 0.12.0

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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +1 -1
  3. package/src/index.js +131 -110
package/README.md CHANGED
@@ -7,6 +7,8 @@ In order to use this, you must have the webdriver for your chosen browser access
7
7
  * Download chromedriver for your browser version
8
8
  * Move the binary to /usr/local/bin
9
9
 
10
+ Running `jsbehave` directly will locate all files that end in `.behave` and will run them.
11
+
10
12
  ## Operations
11
13
 
12
14
  `open <browser>` (note the name for this browser is `default`)
@@ -177,7 +179,7 @@ run action some action
177
179
 
178
180
  ## Custom code
179
181
 
180
- In order to load custom code, put `load funcs <filename>` in your test file.
182
+ In order to load custom code, put `load funcs <filename>` in your test file. Functions can be async.
181
183
 
182
184
  The function should set `module.exports` to an object that looks like the following:
183
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bucky24/jsbehave",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "A module that allows BDD testing for browser based testing in Selenium.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -7,16 +7,27 @@ const path = require("path");
7
7
  const clipboardy = require('clipboardy');
8
8
  const { v4: uuidv4 } = require('uuid');
9
9
 
10
- const fileName = process.argv[2];
10
+ let fileNames = [];
11
+ if (process.argv.length > 2) {
12
+ fileNames.push(process.argv[2]);
13
+ } else {
14
+ const rootDir = process.cwd();
15
+ const entries = fs.readdirSync(rootDir, {
16
+ recursive: true,
17
+ withFileTypes: true,
18
+ });
19
+
20
+ fileNames = entries
21
+ .filter(e => e.isFile() && e.name.endsWith("behave"))
22
+ .map(e => path.join(e.path, e.name));
23
+ }
24
+
11
25
  let specificTest = null;
12
26
 
13
27
  if (process.argv.length > 3) {
14
28
  specificTest = process.argv[3];
15
29
  }
16
30
 
17
- const contents = fs.readFileSync(fileName, "utf-8");
18
- const lines = contents.split(EOL);
19
-
20
31
  const now = new Date();
21
32
  const nowDate = `${now.getMonth()+1}-${now.getDate()}-${now.getFullYear()}`;
22
33
 
@@ -543,127 +554,137 @@ async function handleLines(lines) {
543
554
  }
544
555
 
545
556
  (async function main() {
546
- // first pass, consolidate all the code into test blocks
557
+ for (const fileName of fileNames) {
558
+ const contents = fs.readFileSync(fileName, "utf-8");
559
+ const lines = contents.split(EOL);
547
560
 
548
- let startLines = [];
549
- let endLines = [];
561
+ console.log(`Processing ${fileName}`);
550
562
 
551
- let testLines = [];
552
- let inTest = false;
553
- let testName = null;
554
- let allOrEach = null;
555
- let inAction = false;
556
- for (const line of lines) {
557
- if (line === "") {
558
- continue;
559
- }
560
- if (line.startsWith("[test")) {
561
- const reg = RegExp(`^${startTestRegex}$`)
562
- const matches = line.match(reg);
563
+ // first pass, consolidate all the code into test blocks
563
564
 
564
- if (matches) {
565
- if (testLines.length > 0) {
566
- startLines = [...testLines];
567
- }
568
- const params = [...matches];
569
- inTest = true;
570
- testLines = [];
571
- testName = params[1];
572
- }
573
- } else if (line.startsWith("[before")) {
574
- if (line === "[before all]") {
575
- allOrEach = 'all';
576
- } else if (line === "[before each]") {
577
- allOrEach = 'each';
578
- }
579
- } else if (line.startsWith("[after")) {
580
- if (line === "[after all]") {
581
- allOrEach = 'all';
582
- } else if (line === "[after each]") {
583
- allOrEach = 'each';
565
+ let startLines = [];
566
+ let endLines = [];
567
+
568
+ let testLines = [];
569
+ let inTest = false;
570
+ let testName = null;
571
+ let allOrEach = null;
572
+ let inAction = false;
573
+ for (const line of lines) {
574
+ if (line === "") {
575
+ continue;
584
576
  }
585
- } else if (line.startsWith("[action")) {
586
- const reg = RegExp(startActionRegex);
587
- const matches = line.match(reg);
588
- if (matches) {
589
- if (testLines.length > 0) {
590
- startLines = [...testLines];
577
+ if (line.startsWith("[test")) {
578
+ const reg = RegExp(`^${startTestRegex}$`)
579
+ const matches = line.match(reg);
580
+
581
+ if (matches) {
582
+ if (testLines.length > 0) {
583
+ startLines = [...testLines];
584
+ }
585
+ const params = [...matches];
586
+ inTest = true;
587
+ testLines = [];
588
+ testName = params[1];
589
+ }
590
+ } else if (line.startsWith("[before")) {
591
+ if (line === "[before all]") {
592
+ allOrEach = 'all';
593
+ } else if (line === "[before each]") {
594
+ allOrEach = 'each';
595
+ }
596
+ } else if (line.startsWith("[after")) {
597
+ if (line === "[after all]") {
598
+ allOrEach = 'all';
599
+ } else if (line === "[after each]") {
600
+ allOrEach = 'each';
601
+ }
602
+ } else if (line.startsWith("[action")) {
603
+ const reg = RegExp(startActionRegex);
604
+ const matches = line.match(reg);
605
+ if (matches) {
606
+ if (testLines.length > 0) {
607
+ startLines = [...testLines];
608
+ }
609
+ const params = [...matches];
610
+ inAction = true;
611
+ testLines = [];
612
+ testName = params[1];
591
613
  }
592
- const params = [...matches];
593
- inAction = true;
594
- testLines = [];
595
- testName = params[1];
596
614
  }
597
- }
598
615
 
599
- testLines.push(line);
616
+ testLines.push(line);
600
617
 
601
- if (line.startsWith("[endtest")) {
602
- inTest = false;
603
- allTests[testName] = [...testLines]
604
- testName = null;
605
- testLines = [];
606
- } else if (line === "[endbefore]") {
607
- if (allOrEach === "all") {
608
- beforeAll.push([...testLines])
609
- testLines = [];
610
- } else if (allOrEach = "every") {
611
- beforeEach.push([...testLines])
612
- testLines = [];
613
- }
614
- allOrEach = null;
615
- } else if (line === "[endafter]") {
616
- if (allOrEach === "all") {
617
- afterAll.push([...testLines])
618
+ if (line.startsWith("[endtest")) {
619
+ inTest = false;
620
+ allTests[testName] = [...testLines]
621
+ testName = null;
618
622
  testLines = [];
619
- } else if (allOrEach = "every") {
620
- afterEach.push([...testLines])
623
+ } else if (line === "[endbefore]") {
624
+ if (allOrEach === "all") {
625
+ beforeAll.push([...testLines])
626
+ testLines = [];
627
+ } else if (allOrEach = "every") {
628
+ beforeEach.push([...testLines])
629
+ testLines = [];
630
+ }
631
+ allOrEach = null;
632
+ } else if (line === "[endafter]") {
633
+ if (allOrEach === "all") {
634
+ afterAll.push([...testLines])
635
+ testLines = [];
636
+ } else if (allOrEach = "every") {
637
+ afterEach.push([...testLines])
638
+ testLines = [];
639
+ }
640
+ allOrEach = null;
641
+ } else if (line === "[endaction]") {
642
+ inAction = false;
643
+ allActions[testName] = [...testLines]
644
+ testName = null;
621
645
  testLines = [];
622
646
  }
623
- allOrEach = null;
624
- } else if (line === "[endaction]") {
625
- inAction = false;
626
- allActions[testName] = [...testLines]
627
- testName = null;
628
- testLines = [];
629
647
  }
630
- }
631
648
 
632
- if (testLines.length > 0) {
633
- endLines = [...testLines];
634
- }
635
-
636
- if (specificTest) {
637
- if (!allTests[specificTest]) {
638
- console.log("No test case found for '" + specificTest + "'");
639
- console.log(Object.keys(allTests));
640
- return;
649
+ if (testLines.length > 0) {
650
+ endLines = [...testLines];
641
651
  }
642
652
 
643
- await handleLines(startLines);
644
- console.log("Running beforeAll");
645
- for (const before of beforeAll) {
646
- await handleLines(before);
647
- }
648
- await runTest(specificTest, true);
649
- console.log("Running afterAll");
650
- for (const after of afterAll) {
651
- await handleLines(after);
652
- }
653
- await handleLines(endLines);
654
- } else {
655
- await handleLines(startLines);
656
- console.log("Running beforeAll");
657
- for (const before of beforeAll) {
658
- await handleLines(before);
659
- }
660
- for (const testName in allTests) {
661
- await runTest(testName, true);
662
- }
663
- console.log("Running afterAll");
664
- for (const after of afterAll) {
665
- await handleLines(after);
653
+ if (specificTest) {
654
+ if (!allTests[specificTest]) {
655
+ console.log("No test case found for '" + specificTest + "'");
656
+ console.log(Object.keys(allTests));
657
+ return;
658
+ }
659
+
660
+ await handleLines(startLines);
661
+ console.log("Running beforeAll");
662
+ for (const before of beforeAll) {
663
+ await handleLines(before);
664
+ }
665
+ await runTest(specificTest, true);
666
+ console.log("Running afterAll");
667
+ for (const after of afterAll) {
668
+ await handleLines(after);
669
+ }
670
+ await handleLines(endLines);
671
+ } else {
672
+ await handleLines(startLines);
673
+ console.log("Running beforeAll");
674
+ for (const before of beforeAll) {
675
+ await handleLines(before);
676
+ }
677
+ for (const testName in allTests) {
678
+ await runTest(testName, true);
679
+ }
680
+ console.log("Running afterAll");
681
+ for (const after of afterAll) {
682
+ await handleLines(after);
683
+ }
684
+ await handleLines(endLines);
666
685
  }
667
- await handleLines(endLines);
668
686
  }
687
+
688
+ // force terminate
689
+ process.exit(0);
669
690
  })();