diff --git a/.github/workflows/test.yml-template b/.github/workflows/test.yml-template new file mode 100644 index 00000000..44ac4e96 --- /dev/null +++ b/.github/workflows/test.yml-template @@ -0,0 +1,29 @@ +name: Test + +on: + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm start & sleep 5 && npm test + - name: Upload tests report(cypress mochaawesome merged HTML report) + if: ${{ always() }} + uses: actions/upload-artifact@v2 + with: + name: report + path: reports diff --git a/src/scripts/main.js b/src/scripts/main.js index 2cdcd10c..eeaf93a8 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -18,10 +18,32 @@ const food = { }, }; -const tree = document.querySelector('#tree'); - function createTree(element, data) { - // WRITE YOUR CODE HERE + if (!element || !data || Object.keys(data).length === 0) { + return; + } + + const ul = document.createElement('ul'); + + for (const key in data) { + const li = document.createElement('li'); + + li.textContent = key; + + createTree(li, data[key]); + + ul.append(li); + } + + element.append(ul); +} + +let tree = document.querySelector('#tree'); + +if (!tree) { + tree = document.createElement('div'); + tree.id = 'tree'; + document.body.append(tree); } createTree(tree, food);