Skip to content

Commit

Permalink
Fix #16: properly handle irrelevant describe section (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-mueller authored Oct 21, 2023
1 parent d0ce22f commit 98a15ab
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
22 changes: 17 additions & 5 deletions test-cockpit-npm-jest.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,29 @@ Return a string that is understood by the --testNamePattern switch of jest."
(save-excursion
(test-cockpit-npm-jest--find-marker "describe")))

(defun test-cockpit-npm-jest--end-point-of-entity ()
"Find the end position of the current test or test group supposing being at its begin."
(save-excursion
(backward-char)
(forward-sexp)
(point)))

(defun test-cockpit-npm-jest--find-marker (marker-regexp)
"Find the next marker defined by MARKER-REGEXP.
A marker is a marker for a test or a test group understood by
--testNamePattern of jest."
(let ((forward-sexp-function nil))
(let ((forward-sexp-function nil)
(old-point (point)))
(when-let ((start-pos (test-cockpit-npm-jest--goto-initial-marker marker-regexp)))
(test-cockpit-npm-jest--skip-potential-each-table)
(when-let ((result-string (test-cockpit-npm-jest--unqote-test-name-sexp
(test-cockpit-npm-jest--test-name-sexp))))
`(,start-pos ,result-string)))))
(if (< (test-cockpit-npm-jest--end-point-of-entity) old-point)
(progn
(goto-char start-pos)
(test-cockpit-npm-jest--find-marker marker-regexp))
(test-cockpit-npm-jest--skip-potential-each-table)
(when-let ((result-string (test-cockpit-npm-jest--unqote-test-name-sexp
(test-cockpit-npm-jest--test-name-sexp))))
`(,start-pos ,result-string))))))

(defun test-cockpit-npm-jest--goto-initial-marker (marker-regexp)
"Go to the initial test or test group marker defined by MARKER-REGEXP.
Expand Down
40 changes: 38 additions & 2 deletions test/test-npm-jest.el-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
"))
})"))
(with-temp-js-buffer
(insert buffer-contents)
(goto-char 190)
Expand All @@ -372,8 +372,44 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
"))
})"))
(with-temp-js-buffer
(insert buffer-contents)
(goto-char 288)
(should (equal (test-cockpit-npm-jest--find-current-test) "AppComponent should create the test app")))))


(ert-deftest test-npm-empty-describe-block-before-it ()
(let ((buffer-contents "
describe('outer', () => {
describe('middle', () => {
});
it('foo', async () => {
expect(2).toBe(2); // HERE
});
});
"))
(with-temp-js-buffer
(insert buffer-contents)
(goto-char 100)
(should (equal (test-cockpit-npm-jest--find-current-test) "outer foo")))))

(ert-deftest test-npm-non-empty-describe-block-before-it ()
(let ((buffer-contents "
describe('outer', () => {
describe('middle', () => {
it('bar', async () => {
expect(2).toBe(2); // HERE
});
});
it('foo', async () => {
expect(2).toBe(2); // HERE
});
});
"))
(with-temp-js-buffer
(insert buffer-contents)
(goto-char 150)
(should (equal (test-cockpit-npm-jest--find-current-test) "outer foo")))))

0 comments on commit 98a15ab

Please sign in to comment.