-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix adding IDs to the tests #186
base: master
Are you sure you want to change the base?
Conversation
@AZANIR please add unit tests for the functionality you implemented |
@@ -13,82 +13,99 @@ const { parseTest, parseSuite, replaceSuiteTitle } = require('./helpers'); | |||
* @param {*} opts | |||
* @returns | |||
*/ | |||
function updateIdsCommon(testData, testomatioMap, workDir, opts = {}) { | |||
function updateIdsCommon(testData, testomatioMap, workDir = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted opts
workDir = {})
- ??
line: getLineNumber(path), | ||
code: getCode(source, getLineNumber(path), getEndLineNumber(path), isLineNumber), | ||
file, | ||
skipped: true, | ||
tags: ['@todo'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you overwrite existent tags
const files = []; | ||
let duplicateTests = 0; | ||
let duplicateSuites = 0; | ||
|
||
debug('Test data:', testData); | ||
|
||
for (const testArr of testData) { | ||
if (!testArr.length) continue; | ||
if (!testArr || !testArr.length) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!testArr?.length
fs.writeFileSync(file, fileContent); | ||
for (const suite of data.suites) { | ||
if (!suite) continue; | ||
const suiteIndex = suite || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't assign empty string; if suiteIndex is empty - skip
and you have already checked if suite exists on the line above
const suiteWithoutTags = suite.replace(TAG_REGEX, '').trim(); | ||
|
||
const currentSuiteId = parseSuite(suiteIndex); | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add comment what is happening here?
const newTitle = suite.slice().replace(suiteId, '').trim(); | ||
fileContent = fileContent.replace(suite, newTitle); | ||
if (suiteIds.includes(suiteId) || (dangerous && suiteId)) { | ||
const newTitle = suite.slice().replace(suiteId, '').trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does slice
does in this case?
debug(` Previous ID detected in suite '${suiteIndex}'`); | ||
duplicateSuites++; | ||
for (const data of testArr) { | ||
if (!data || !data.suites || !Array.isArray(data.suites)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!data?.suites
let testIndex = `${test.suites[0] || ''}#${test.name}`; | ||
debug('testIndex', testIndex); | ||
|
||
// this is not test; its test.skip() annotation inside a test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't remove this code
delete testomatioMap.tests[testWithoutTags]; | ||
const testName = test.name || ''; | ||
|
||
if (testName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace if (test.name)
with if (!test.name) continue
and you will get rid of 1 level of nesting
debug(`Previous ID detected in test '${testIndex}'`); | ||
duplicateTests++; | ||
if (!test) { | ||
debug('Invalid test:', test); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will not have any output here
🌀 Tests overview by Testomatio Found 128 mocha tests in 16 files ✔️ Added 128 tests+ analyzer: can import analyzer from main index
+ analyzer: should parse all mocha files
+ analyzer: should parse all typescript files
+ analyzer: should exclude dir in file name if dir specified
+ analyzer: should include full dir in file name
+ analyzer: should avoid node_modules
+ analyzer: should read ` char
+ analyzer: should not load dirs as files
+ analyzer: env variable params: should prepend a dir from env variable
+ codeceptjs parser: create todo tests: should parse codecept file
+ codeceptjs parser: create todo tests: should include code
+ codeceptjs parser: Parse CodeceptJS tags: should include tags
+ codeceptjs parser: Parse CodeceptJS tags & datatable: should include data and tags
+ codeceptjs parser: Parse CodeceptJS hooks code - default opts: should include Before hook code
+ codeceptjs parser: Parse CodeceptJS hooks code - default opts: should include BeforeSuite hook code
+ codeceptjs parser: Parse CodeceptJS hooks code - default opts: should include AfterSuite hook code
+ codeceptjs parser: [opts.noHooks = true] Parse CodeceptJS hooks code: should exclude Before hook code
+ codeceptjs parser: [opts.noHooks = true] Parse CodeceptJS hooks code: should exclude BeforeSuite hook code
+ codeceptjs parser: [opts.noHooks = true] Parse CodeceptJS hooks code: should exclude AfterSuite hook code
+ codeceptjs parser: Parse CodeceptJS test with --line-numbers option: [lineNumbers=true opts] each section should include line-number as part of code section
+ codeceptjs parser: Parse CodeceptJS test with --line-numbers option: [no SET the lineNumbers opts] should exclude line-number
+ codeceptjs parser: Parse CodeceptJS test with --line-numbers option: [noHooks=true + lineNumbers=true opts] line-number as part of code section
+ Comment: should refer to proper skipped line in comment
+ Decorator: should print markdown
+ Decorator: should validate tests with empty titles
+ Decorator: should print markdown2
+ jasmine parser: jasmine tests: should parse jasmine file
+ jasmine parser: jasmine tests: should include code
+ jest parser: jest tests: should parse jest file
+ jest parser: jest tests: should include code
+ jest parser: exclusive tests: should throw an error if a file contains .only
+ jest parser: hooks tests - default opts: should include beforeAll hook code
+ jest parser: hooks tests - default opts: should include beforeEach hook code
+ jest parser: hooks tests - default opts: should include afterAll hook code
+ jest parser: [opts.noHooks = true] hooks tests: should exclude beforeAll hook code
+ jest parser: [opts.noHooks = true] hooks tests: should exclude beforeEach hook code
+ jest parser: [opts.noHooks = true] hooks tests: should exclude after hook code
+ jest parser: test with --line-numbers option: [lineNumbers=true opts] each section should include line-number as part of code section
+ jest parser: test with --line-numbers option: [no SET the lineNumbers opts] should exclude line-number
+ jest parser: test with --line-numbers option: [noHooks=true + lineNumbers=true opts] line-number as part of code section
+ mocha parser: mocha tests: should parse mocha file
+ mocha parser: cypress tests: should parse cypress file
+ mocha parser: cypress tests: should include code
+ mocha parser: graphql tests: should parse codeceptjs internal test
+ mocha parser: Cypress: hooks tests: should include before hook code by default
+ mocha parser: Cypress: hooks tests: should include beforeEach hook code by default
+ mocha parser: Cypress: hooks tests: should include after hook code by default
+ mocha parser: [opts.noHooks = true] Cypress: hooks code: should exclude before hook code
+ mocha parser: [opts.noHooks = true] Cypress: hooks code: should exclude beforeEach hook code
+ mocha parser: [opts.noHooks = true] Cypress: hooks code: should exclude after hook code
+ mocha parser: Cypress: test with --line-numbers option: [lineNumbers=true opts] each section should include line-number as part of code section
+ mocha parser: Cypress: test with --line-numbers option: [no SET the lineNumbers opts] should exclude line-number
+ mocha parser: Cypress: test with --line-numbers option: [noHooks=true + lineNumbers=true opts] line-number as part of code section
+ newman parser: should parse newman collection
+ newman parser: should properly get test name
+ newman parser: should properly get suites for test inside nested folder
+ newman parser: should properly get suite for test within collection (not in any folder)
+ playwright parser: should parse basic playwright-js tests
+ playwright parser: should forbid describe.only tests
+ playwright parser: should parse basic playwright-ts tests
+ playwright parser: should parse multiple playwright-js tests
+ playwright parser: should parse multiple playwright-ts tests
+ playwright parser: should update playwright suite if no suite set
+ playwright parser: tags: should parse playwright-ts test with signle tag on the same line
+ playwright parser: tags: should parse playwright-ts test with opening brace on the same line and signle tag on the next line
+ playwright parser: tags: should parse playwright-ts test with signle tag on the next line
+ playwright parser: tags: should parse playwright-js test with multiple tags
+ playwright parser: tags: should parse playwright-js test with multiple tags on multiple lines
+ playwright parser: tags: should parse playwright-ts tests with params
+ playwright parser: tags: should parse playwright-js tests with annotation
+ playwright parser: tags: should parse playwright-js tests with annotation including fixme
+ playwright parser: tags: should parse playwright-ts tests with annotations
+ playwright parser: tags: should parse playwright test with test.skip annotation inside a test
+ playwright parser: tags: should parse playwright-js tests with skip() annotation for the description and test sections
+ playwright parser: tags: should parse playwright-js tests with fixme() annotation for the description and test sections
+ playwright parser: Parse Playwright hooks code - default opts: should include beforeAll hook code
+ playwright parser: Parse Playwright hooks code - default opts: should include beforeEach hook code
+ playwright parser: Parse Playwright hooks code - default opts: should include afterAll hook code
+ playwright parser: [opts.noHooks = true] Parse Playwright hooks code: should exclude beforeAll hook code
+ playwright parser: [opts.noHooks = true] Parse Playwright hooks code: should exclude beforeEach hook code
+ playwright parser: [opts.noHooks = true] Parse Playwright hooks code: should exclude afterAll hook code
+ playwright parser: Default playwright file parsing : should parse basic playwright-ts DEMO tests ("todo" name as part of inner function args)
+ playwright parser: Default playwright file parsing : should return suite name if used test.describe without parallel mode
+ playwright parser: Default playwright file parsing : should return suite name if used test.describe.parallel mode
+ playwright parser: Default playwright file parsing : should return suite name if used test.describe.serial mode
+ playwright parser: test with --line-numbers option: [lineNumbers=true opts] each section should include line-number as part of code section
+ playwright parser: test with --line-numbers option: [no SET the lineNumbers opts] should exclude line-number
+ playwright parser: test with --line-numbers option: [noHooks=true + lineNumbers=true opts] line-number as part of code section
+ qunit parser: qunit tests: should parse qunit file
+ testcafe parser: Testcafe tests: should parse testcafe file
+ testcafe parser: Testcafe tests: should include testcafe code
+ UpdateIds FS: should add suite and test ids
+ UpdateIds FS: should clean suite and test ids safely
+ UpdateIds FS: should clean suite and test ids unsafely
+ update ids tests(codeseptJS adapter): [codeseptJS examples] includes Feature + Scenario: [js file]: file includes Feature + one Scenario
+ update ids tests(codeseptJS adapter): [codeseptJS examples] includes Feature + Scenario: [js file]: test file does not include Feature, only Scenario
+ update ids tests(codeseptJS adapter): [codeseptJS examples] includes Feature + Scenario: [js file]: test file does not include Scenario, only Feature
+ update ids tests(codeseptJS adapter): [codeseptJS examples] clean-ids: can remove ids from the file with Scenario only
+ update ids tests(codeseptJS adapter): [codeseptJS examples] clean-ids: can remove ids form the Feature & Scenario
+ update ids tests(playwright adapter): [Playwright examples] includes/no includes main suite: [ts file]: test file includes suite with tests
+ update ids tests(playwright adapter): [Playwright examples] includes/no includes main suite: [ts file]: test file does not include suite name, only tests
+ update ids tests(playwright adapter): [Playwright examples] includes/no includes main suite: [ts file]: test file test.describe.parallel mode should returns updated title.
+ update ids tests(playwright adapter): [Playwright examples] lines processing: [ts file]: the same import name as suite name
+ update ids tests(playwright adapter): [Playwright examples] lines processing: [ts file]: test file without imports should update only suite & test name
+ update ids tests(playwright adapter): [Playwright examples] lines processing: [js file]: the same require name as suite name
+ update ids tests(playwright adapter): [Playwright examples] lines processing: [js file]: suite name as a new line
+ update ids tests(playwright adapter): [Playwright examples] lines processing: test.skip() annotation inside a test is propersly processed
+ update ids tests(playwright adapter): [Playwright examples] clean-ids for the --typescript mode: can remove ids from the file with suite
+ update ids tests(playwright adapter): [Playwright examples] clean-ids for the --typescript mode: can remove ids if no suites in the file
+ update ids: update-ids: should update id by title
+ update ids: update-ids: should update id with tags by title
+ update ids: update-ids: updates ids from server
+ update ids: update-ids: ignore duplicates for ids from server
+ update ids: update-ids: should not update other strings in file
+ update ids: update-ids: allows multi-line titles
+ update ids: update-ids: respects string literals
+ update ids: update-ids: respects variables in string literals
+ update ids: update-ids: respects variables in string literals and JSON report mode
+ update ids: update-ids: respects variables in string literals in double param and JSON report mode
+ update ids: update-ids: works ok with empty files
+ update ids: update-ids: supports typescript
+ update ids: update-ids: supports typescript with types
+ update ids: update-ids: should not reformat the Array code with --typescript option
+ update ids: clean-ids: cleans up ids from strings
+ update ids: clean-ids: cleans up ids from string literals
+ update ids: clean-ids: unsafely cleans up ids from string literals
+ update ids: clean-ids: can remove ids from typescript
+ util functions: #replaceAtPoint 📑 List all tests
📝 tests/updateIds_codeceptjs_test.js
📝 tests/updateIds_playwright_test.js
|
This MR fixes the functionality for adding unique IDs not only to all tests but also to test suites. The ID generation has been corrected to ensure proper assignment to both tests and suites.
testomatio/app#954
Changes:
Fixed the logic for assigning unique IDs to tests and suites.