Skip to content

Commit 13e87e3

Browse files
committed
ci: add github workflows
1 parent 425dcf1 commit 13e87e3

7 files changed

Lines changed: 139 additions & 37 deletions

File tree

.github/workflows/workflow.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: nvim-dap-ui Workflow
2+
on: [push]
3+
jobs:
4+
style:
5+
name: style
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- uses: JohnnyMorganz/stylua-action@1.0.0
10+
with:
11+
token: ${{ secrets.GITHUB_TOKEN }}
12+
args: --check lua/ tests/
13+
14+
tests:
15+
name: tests
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- run: date +%F > todays-date
20+
- name: Restore cache for today's nightly.
21+
uses: actions/cache@v2
22+
with:
23+
path: _neovim
24+
key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }}
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 16
30+
cache: 'yarn'
31+
32+
- name: Prepare dependencies
33+
run: |
34+
npm install --global yarn
35+
bash ./scripts/setup_tests
36+
37+
- name: Run tests
38+
run: |
39+
curl -OL https://raw.githubusercontent.com/norcalli/bot-ci/master/scripts/github-actions-setup.sh
40+
source github-actions-setup.sh nightly-x64
41+
bash ./scripts/test -t 30000
42+
43+
release:
44+
name: release
45+
if: ${{ github.ref == 'refs/heads/master' }}
46+
needs:
47+
- style
48+
- tests
49+
runs-on: ubuntu-20.04
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v2
53+
with:
54+
fetch-depth: 0
55+
- name: Setup Node.js
56+
uses: actions/setup-node@v1
57+
with:
58+
node-version: 16
59+
- name: Release
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: npx semantic-release
63+

lua/dap-vscode-js/session.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function M.unregister_session(session)
4949
sessions[session] = nil
5050
end
5151

52+
function M.is_session_registered(session)
53+
return not not sessions[session]
54+
end
55+
5256
local function get_breakpoints(pid)
5357
breakpoints[pid] = breakpoints[pid] or {}
5458
return breakpoints[pid]

scripts/test

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
#!/bin/bash
22

3+
TIMEOUT=2000
4+
5+
while getopts ":t:" options; do
6+
case "${options}" in
7+
t)
8+
if [ -n "${OPTARG}" ]; then
9+
TIMEOUT=${OPTARG}
10+
fi
11+
;;
12+
esac
13+
done
14+
15+
export PLENARY_TEST_TIMEOUT=$TIMEOUT
16+
17+
shift $(($OPTIND - 1))
18+
319
tempfile=".test_output.tmp"
420

521
if [[ -n $1 ]]; then
6-
nvim --headless --clean --noplugin -u tests/init.vim -c "PlenaryBustedFile $1 {sequential=true}" | tee "${tempfile}"
22+
nvim --headless --clean --noplugin -u tests/init.vim -c "PlenaryBustedFile $1" | tee "${tempfile}"
723
else
824
nvim --headless --clean --noplugin -u tests/init.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/init.vim'}" | tee "${tempfile}"
925
fi

tests/init.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set rtp+=./lib/nvim-dap
66
set rtp+=./lib/nvim-dap-ui
77
set rtp+=./tests
88

9-
let $PLENARY_TEST_TIMEOUT=2000
9+
" let $PLENARY_TEST_TIMEOUT=60000
1010

1111
runtime! plugin/plenary.vim
1212
lua DEBUGGER_PATH="./lib/vscode-js-debug"

tests/integration/jest_spec.lua

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local breakpoints = require("dap.breakpoints")
22
local async = require("plenary.async.tests")
33
local wrap = require("plenary.async.async").wrap
44
local dapjs = require("dap-vscode-js")
5+
local js_session = require"dap-vscode-js.session"
56
local dap = require("dap")
67
local test_utils = require("__dap_js_test_util")
78
local config = require("dap-vscode-js.config")
@@ -12,7 +13,7 @@ local launch_config = {
1213
type = "pwa-node",
1314
request = "launch",
1415
name = "Debug Jest Tests",
15-
trace = true,
16+
-- trace = true,
1617
runtimeExecutable = "node",
1718
runtimeArgs = {
1819
"./node_modules/jest/bin/jest.js",
@@ -34,38 +35,35 @@ describe("pwa-node jest", function()
3435
async.it(
3536
"receives stdout from terminal",
3637
wrap(function(done)
37-
local term_lines = {}
38+
local terminated = false
3839

39-
local terminated = false
40-
local cleanup
40+
local lines_found = {
41+
["Tests: 1 failed, 1 passed, 2 total"] = false,
42+
["Ran all test suites."] = false,
43+
["Waiting for the debugger to disconnect..."] = false,
44+
}
4145

4246
local function try_exit()
43-
if terminated and #term_lines == 98 then
44-
assert.equal(term_lines[92], "Tests: 1 failed, 1 passed, 2 total")
45-
46-
cleanup()
47-
done()
48-
end
47+
if terminated and vim.tbl_count(lines_found) == 0 then
48+
done()
49+
end
4950
end
5051

51-
cleanup = test_utils.get_terminal_remote(function(lines)
52+
test_utils.get_terminal_remote(function(lines)
5253
for _, line in ipairs(lines) do
53-
table.insert(term_lines, line)
54+
lines_found[line] = nil
5455
end
5556

5657
try_exit()
5758
end)
5859

5960
test_utils.open_test("jest/integration.test.ts")
6061

61-
test_utils.add_listener("before", "event_output", function(session, body)
62-
print(body.output)
63-
end)
62+
test_utils.on_session_end(function ()
63+
terminated = true
6464

65-
test_utils.add_listener("before", "event_terminated", function()
66-
terminated = true
67-
try_exit()
68-
end)
65+
try_exit()
66+
end)
6967

7068
dap.run(launch_config)
7169
end, 1)

tests/integration/node_spec.lua

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe("pwa-node", function()
2323
end)
2424

2525
describe("typescript", function()
26+
2627
async.it(
2728
"can be debugged with simple config",
2829
wrap(function(done)
@@ -53,7 +54,7 @@ describe("pwa-node", function()
5354
try_exit()
5455
end)
5556

56-
test_utils.add_listener("after", "event_terminated", function(session, body)
57+
test_utils.on_session_end(function ()
5758
termination_happened = true
5859

5960
try_exit()
@@ -74,29 +75,32 @@ describe("pwa-node", function()
7475
test_utils.add_listener("after", "event_stopped", function(session, body)
7576
assert.equal(body.reason, "breakpoint")
7677

77-
vim.defer_fn(function()
78-
local bps = breakpoints.get(bufexpr)[bufexpr]
78+
local bps = breakpoints.get(bufexpr)[bufexpr]
79+
80+
assert.equal(#bps, 1)
7981

80-
assert.equal(#bps, 1)
82+
local bp_signs = test_utils.get_breakpoint_signs(bufexpr)
8183

82-
local bp_signs = test_utils.get_breakpoint_signs(bufexpr)
84+
assert.equal(#bp_signs, 1)
8385

84-
for _, bp in ipairs(bp_signs) do
85-
for _, sign in ipairs(bp.signs) do
86-
assert.equal(sign.name, "DapBreakpoint")
87-
end
88-
end
86+
for _, bp in ipairs(bp_signs) do
87+
assert.equal(#bp.signs, 1)
8988

90-
dap.continue()
91-
end, 10)
89+
for _, sign in ipairs(bp.signs) do
90+
assert.equal(sign.name, "DapBreakpoint")
91+
end
92+
end
93+
94+
done()
9295
end)
9396

94-
test_utils.add_listener("after", "event_terminated", function(session, body)
97+
test_utils.on_session_end(function ()
9598
done()
9699
end)
97100

98101
dap.run(launch_config)
99102
end, 1)
100103
)
104+
101105
end)
102106
end)

tests/lua/__dap_js_test_util.lua

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ local dap = require("dap")
44
local dap_bps = require("dap.breakpoints")
55
local dapjs = require("dap-vscode-js")
66
local dapjs_utils = require("dap-vscode-js.utils")
7+
local js_session = require("dap-vscode-js.session")
78

89
local dap_ns = "dap_breakpoints"
910

1011
M.id = "___dap_js_test"
1112
local util_id = "___dap_js_test_utils"
1213

13-
local current_session
14+
-- local current_session
15+
local current_sessions = { }
1416

1517
function M.clear_listeners()
1618
for _, time in ipairs({ "before", "after" }) do
@@ -32,6 +34,7 @@ function M.reset()
3234
M.clear_listeners()
3335
M.clear_config()
3436
M.clear_breakpoints()
37+
current_sessions = { }
3538
end
3639

3740
function M.set_breakpoint(lnum, bufnr, opts)
@@ -40,21 +43,35 @@ end
4043

4144
function M.add_listener(time, event_or_command, callback)
4245
dap.listeners[time][event_or_command][M.id] = function(session, ...)
43-
if session ~= current_session then
46+
if not current_sessions[session] then
4447
return
4548
end
4649

4750
callback(session, ...)
4851
end
4952
end
5053

54+
function M.on_session_end(callback)
55+
M.add_listener('after', 'event_terminated', function (session, ...)
56+
current_sessions[session] = nil
57+
58+
local active_sessions = vim.tbl_filter(function (el)
59+
return js_session.is_session_registered(el)
60+
end, vim.tbl_keys(current_sessions))
61+
62+
if #active_sessions == 0 then
63+
callback(session, ...)
64+
end
65+
end)
66+
end
67+
5168
function M.setup_dapjs(config)
5269
dapjs.setup(vim.tbl_extend("force", {
5370
debugger_path = DEBUGGER_PATH,
5471
}, config or {}))
5572

5673
dap.listeners.before["event_initialized"][util_id] = function(session)
57-
current_session = session
74+
current_sessions[session] = true
5875
end
5976
end
6077

0 commit comments

Comments
 (0)