@bucky24/jsbehave 0.11.0 → 0.12.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.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +1 -1
  3. package/src/index.js +133 -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.1",
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,29 @@ 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 => {
22
+ return e.isFile() && e.name.endsWith(".behave");
23
+ })
24
+ .map(e => path.join(e.path, e.name));
25
+ }
26
+
11
27
  let specificTest = null;
12
28
 
13
29
  if (process.argv.length > 3) {
14
30
  specificTest = process.argv[3];
15
31
  }
16
32
 
17
- const contents = fs.readFileSync(fileName, "utf-8");
18
- const lines = contents.split(EOL);
19
-
20
33
  const now = new Date();
21
34
  const nowDate = `${now.getMonth()+1}-${now.getDate()}-${now.getFullYear()}`;
22
35
 
@@ -543,127 +556,137 @@ async function handleLines(lines) {
543
556
  }
544
557
 
545
558
  (async function main() {
546
- // first pass, consolidate all the code into test blocks
559
+ for (const fileName of fileNames) {
560
+ const contents = fs.readFileSync(fileName, "utf-8");
561
+ const lines = contents.split(EOL);
547
562
 
548
- let startLines = [];
549
- let endLines = [];
563
+ console.log(`Processing ${fileName}`);
550
564
 
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);
565
+ // first pass, consolidate all the code into test blocks
563
566
 
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';
567
+ let startLines = [];
568
+ let endLines = [];
569
+
570
+ let testLines = [];
571
+ let inTest = false;
572
+ let testName = null;
573
+ let allOrEach = null;
574
+ let inAction = false;
575
+ for (const line of lines) {
576
+ if (line === "") {
577
+ continue;
584
578
  }
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];
579
+ if (line.startsWith("[test")) {
580
+ const reg = RegExp(`^${startTestRegex}$`)
581
+ const matches = line.match(reg);
582
+
583
+ if (matches) {
584
+ if (testLines.length > 0) {
585
+ startLines = [...testLines];
586
+ }
587
+ const params = [...matches];
588
+ inTest = true;
589
+ testLines = [];
590
+ testName = params[1];
591
+ }
592
+ } else if (line.startsWith("[before")) {
593
+ if (line === "[before all]") {
594
+ allOrEach = 'all';
595
+ } else if (line === "[before each]") {
596
+ allOrEach = 'each';
597
+ }
598
+ } else if (line.startsWith("[after")) {
599
+ if (line === "[after all]") {
600
+ allOrEach = 'all';
601
+ } else if (line === "[after each]") {
602
+ allOrEach = 'each';
603
+ }
604
+ } else if (line.startsWith("[action")) {
605
+ const reg = RegExp(startActionRegex);
606
+ const matches = line.match(reg);
607
+ if (matches) {
608
+ if (testLines.length > 0) {
609
+ startLines = [...testLines];
610
+ }
611
+ const params = [...matches];
612
+ inAction = true;
613
+ testLines = [];
614
+ testName = params[1];
591
615
  }
592
- const params = [...matches];
593
- inAction = true;
594
- testLines = [];
595
- testName = params[1];
596
616
  }
597
- }
598
617
 
599
- testLines.push(line);
618
+ testLines.push(line);
600
619
 
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])
620
+ if (line.startsWith("[endtest")) {
621
+ inTest = false;
622
+ allTests[testName] = [...testLines]
623
+ testName = null;
618
624
  testLines = [];
619
- } else if (allOrEach = "every") {
620
- afterEach.push([...testLines])
625
+ } else if (line === "[endbefore]") {
626
+ if (allOrEach === "all") {
627
+ beforeAll.push([...testLines])
628
+ testLines = [];
629
+ } else if (allOrEach = "every") {
630
+ beforeEach.push([...testLines])
631
+ testLines = [];
632
+ }
633
+ allOrEach = null;
634
+ } else if (line === "[endafter]") {
635
+ if (allOrEach === "all") {
636
+ afterAll.push([...testLines])
637
+ testLines = [];
638
+ } else if (allOrEach = "every") {
639
+ afterEach.push([...testLines])
640
+ testLines = [];
641
+ }
642
+ allOrEach = null;
643
+ } else if (line === "[endaction]") {
644
+ inAction = false;
645
+ allActions[testName] = [...testLines]
646
+ testName = null;
621
647
  testLines = [];
622
648
  }
623
- allOrEach = null;
624
- } else if (line === "[endaction]") {
625
- inAction = false;
626
- allActions[testName] = [...testLines]
627
- testName = null;
628
- testLines = [];
629
649
  }
630
- }
631
650
 
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;
651
+ if (testLines.length > 0) {
652
+ endLines = [...testLines];
641
653
  }
642
654
 
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);
655
+ if (specificTest) {
656
+ if (!allTests[specificTest]) {
657
+ console.log("No test case found for '" + specificTest + "'");
658
+ console.log(Object.keys(allTests));
659
+ return;
660
+ }
661
+
662
+ await handleLines(startLines);
663
+ console.log("Running beforeAll");
664
+ for (const before of beforeAll) {
665
+ await handleLines(before);
666
+ }
667
+ await runTest(specificTest, true);
668
+ console.log("Running afterAll");
669
+ for (const after of afterAll) {
670
+ await handleLines(after);
671
+ }
672
+ await handleLines(endLines);
673
+ } else {
674
+ await handleLines(startLines);
675
+ console.log("Running beforeAll");
676
+ for (const before of beforeAll) {
677
+ await handleLines(before);
678
+ }
679
+ for (const testName in allTests) {
680
+ await runTest(testName, true);
681
+ }
682
+ console.log("Running afterAll");
683
+ for (const after of afterAll) {
684
+ await handleLines(after);
685
+ }
686
+ await handleLines(endLines);
666
687
  }
667
- await handleLines(endLines);
668
688
  }
689
+
690
+ // force terminate
691
+ process.exit(0);
669
692
  })();